home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 5 / Apprentice-Release5.iso / Source Code / Libraries / DCLAP 6d / dclap6d / vibrant / ncbidraw.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-07-05  |  115.5 KB  |  4,952 lines  |  [TEXT/R*ch]

  1. /*   ncbidraw.c
  2. * ===========================================================================
  3. *
  4. *                            PUBLIC DOMAIN NOTICE
  5. *            National Center for Biotechnology Information (NCBI)
  6. *
  7. *  This software/database is a "United States Government Work" under the
  8. *  terms of the United States Copyright Act.  It was written as part of
  9. *  the author's official duties as a United States Government employee and
  10. *  thus cannot be copyrighted.  This software/database is freely available
  11. *  to the public for use. The National Library of Medicine and the U.S.
  12. *  Government do not place any restriction on its use or reproduction.
  13. *  We would, however, appreciate having the NCBI and the author cited in
  14. *  any work or product based on this material
  15. *
  16. *  Although all reasonable efforts have been taken to ensure the accuracy
  17. *  and reliability of the software and data, the NLM and the U.S.
  18. *  Government do not and cannot warrant the performance or results that
  19. *  may be obtained by using this software or data. The NLM and the U.S.
  20. *  Government disclaim all warranties, express or implied, including
  21. *  warranties of performance, merchantability or fitness for any particular
  22. *  purpose.
  23. *
  24. * ===========================================================================
  25. *
  26. * File Name:  ncbidraw.c
  27. *
  28. * Author:  Jonathan Kans
  29. *
  30. * Version Creation Date:   1/1/91
  31. *
  32. * $Revision: 2.20 $
  33. *
  34. * File Description: 
  35. *       Vibrant drawing functions.
  36. *
  37. * Modifications:  
  38. * --------------------------------------------------------------------------
  39. * Date     Name        Description of modification
  40. * -------  ----------  -----------------------------------------------------
  41. *
  42. *
  43. * ==========================================================================
  44. */
  45.  
  46.  
  47. #include <ncbi.h>
  48. #include <ncbidraw.h>
  49. #include <ncbiwin.h>
  50. #include <ncbiport.h>
  51.  
  52. #ifdef VAR_ARGS
  53. #include <varargs.h>
  54. #else
  55. #include <stdarg.h>
  56. #endif
  57.  
  58. Nlm_Boolean  Nlm_nowPrinting = FALSE;
  59.  
  60. #ifdef WIN_MAC
  61. RGBColor  Nlm_RGBforeColor;
  62. RGBColor  Nlm_RGBbackColor;
  63. #endif
  64.  
  65. #ifdef WIN_MSWIN
  66. HWND         Nlm_currentHWnd;
  67. HDC          Nlm_currentHDC;
  68. #endif
  69.  
  70. #ifdef WIN_X
  71. Display      *Nlm_currentXDisplay;
  72. int          Nlm_currentXScreen;
  73. Window       Nlm_currentXWindow;
  74. GC           Nlm_currentXGC;
  75. Nlm_Uint4    Nlm_XbackColor;
  76. Nlm_Uint4    Nlm_XforeColor;
  77. Nlm_IntD     Nlm_XOffset;
  78. Nlm_IntD     Nlm_YOffset;
  79. Nlm_RegioN   Nlm_clpRgn;
  80. #endif
  81.  
  82. Nlm_RegioN   Nlm_updateRgn;
  83. Nlm_RecT     Nlm_updateRect;
  84.  
  85. Nlm_Int2     Nlm_stdAscent;
  86. Nlm_Int2     Nlm_stdDescent;
  87. Nlm_Int2     Nlm_stdLeading;
  88. Nlm_Int2     Nlm_stdFontHeight;
  89. Nlm_Int2     Nlm_stdLineHeight;
  90. Nlm_Int2     Nlm_stdCharWidth;
  91.  
  92. Nlm_FonT     Nlm_systemFont = NULL;
  93. Nlm_FonT     Nlm_programFont = NULL;
  94.  
  95. #define COPY_MODE   1
  96. #define MERGE_MODE  2
  97. #define INVERT_MODE 3
  98. #define ERASE_MODE  4
  99.  
  100. static Nlm_Int2    currentMode = COPY_MODE;
  101.  
  102. static Nlm_FonT    Nlm_fontList = NULL;
  103. #ifndef DCLAP
  104. static 
  105. #endif
  106. Nlm_FonT    Nlm_fontInUse = NULL;
  107.  
  108. static Nlm_RegioN  Nlm_scrollRgn;
  109.  
  110. #ifdef WIN_MAC
  111. static Nlm_Byte  whitePat [] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
  112. static Nlm_Byte  ltGrayPat [] = {0x88, 0x22, 0x88, 0x22, 0x88, 0x22, 0x88, 0x22};
  113. static Nlm_Byte  grayPat [] = {0xAA, 0x55, 0xAA, 0x55, 0xAA, 0x55, 0xAA, 0x55};
  114. static Nlm_Byte  dkGrayPat [] = {0x77, 0xDD, 0x77, 0xDD, 0x77, 0xDD, 0x77, 0xDD};
  115. static Nlm_Byte  blackPat [] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF};
  116.  
  117. static Nlm_Byte  dotPat [] = {0xAA, 0x55, 0xAA, 0x55, 0xAA, 0x55, 0xAA, 0x55};
  118. static Nlm_Byte  dashPat [] = {0xCC, 0xCC, 0x33, 0x33, 0xCC, 0xCC, 0x33, 0x33};
  119.  
  120. static Nlm_Boolean  hasColorQD = FALSE;
  121. #endif
  122.  
  123. #ifdef WIN_MSWIN
  124. static Nlm_Int2    currentPenStyle = PS_SOLID;
  125. static Nlm_Int2    currentPenWidth = 1;
  126. static void        *currentPattern = NULL;
  127.  
  128. static COLORREF    blackColor;
  129. static COLORREF    redColor;
  130. static COLORREF    greenColor;
  131. static COLORREF    blueColor;
  132. static COLORREF    cyanColor;
  133. static COLORREF    magentaColor;
  134. static COLORREF    yellowColor;
  135. static COLORREF    whiteColor;
  136.  
  137. static Nlm_Uint2   blackPat [] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
  138. static Nlm_Uint2   dkGrayPat [] = {0x88, 0x22, 0x88, 0x22, 0x88, 0x22, 0x88, 0x22};
  139. static Nlm_Uint2   grayPat [] = {0xAA, 0x55, 0xAA, 0x55, 0xAA, 0x55, 0xAA, 0x55};
  140. static Nlm_Uint2   ltGrayPat [] = {0x77, 0xDD, 0x77, 0xDD, 0x77, 0xDD, 0x77, 0xDD};
  141. static Nlm_Uint2   whitePat [] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF};
  142.  
  143. static Nlm_Uint2   dotPat [] = {0xAA, 0x55, 0xAA, 0x55, 0xAA, 0x55, 0xAA, 0x55};
  144. static Nlm_Uint2   dashPat [] = {0xCC, 0xCC, 0x33, 0x33, 0xCC, 0xCC, 0x33, 0x33};
  145.  
  146. static HPEN        hBlackPen;
  147. static HPEN        hNullPen;
  148. static HPEN        hWhitePen;
  149. static HBRUSH      hBlackBrush;
  150. static HBRUSH      hDkGrayBrush;
  151. static HBRUSH      hGrayBrush;
  152. static HBRUSH      hHollowBrush;
  153. static HBRUSH      hLtGrayBrush;
  154. static HBRUSH      hNullBrush;
  155. static HBRUSH      hWhiteBrush;
  156. static HFONT       hAnsiFixedFont;
  157. static HFONT       hAnsiVarFont;
  158. static HFONT       hDeviceDefaultFont;
  159. static HFONT       hOemFixedFont;
  160. static HFONT       hSystemFont;
  161. static HFONT       hSystemFixedFont;
  162.  
  163. static TEXTMETRIC  textMetrics;
  164. #endif
  165.  
  166. #ifdef WIN_X
  167. static XFontStruct  *currentFont;
  168. static Pixmap       currentPixmap = 0;
  169. static Nlm_PoinT    currentPoint;
  170. static Nlm_Uint4    currentBkColor;
  171. static Nlm_Uint4    currentFgColor;
  172. static int          currentFunction = GXcopy;
  173. static int          currentFillStyle = FillOpaqueStippled;
  174.  
  175. static Nlm_Uint4    blackColor;
  176. static Nlm_Uint4    redColor;
  177. static Nlm_Uint4    greenColor;
  178. static Nlm_Uint4    blueColor;
  179. static Nlm_Uint4    cyanColor;
  180. static Nlm_Uint4    magentaColor;
  181. static Nlm_Uint4    yellowColor;
  182. static Nlm_Uint4    whiteColor;
  183.  
  184. static Nlm_Uint1    whitePat [] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
  185. static Nlm_Uint1    ltGrayPat [] = {0x88, 0x22, 0x88, 0x22, 0x88, 0x22, 0x88, 0x22};
  186. static Nlm_Uint1    grayPat [] = {0xAA, 0x55, 0xAA, 0x55, 0xAA, 0x55, 0xAA, 0x55};
  187. static Nlm_Uint1    dkGrayPat [] = {0x77, 0xDD, 0x77, 0xDD, 0x77, 0xDD, 0x77, 0xDD};
  188. static Nlm_Uint1    blackPat [] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF};
  189.  
  190. static Nlm_Uint1    dotPat [] = {0xAA, 0x55, 0xAA, 0x55, 0xAA, 0x55, 0xAA, 0x55};
  191. static Nlm_Uint1    dashPat [] = {0xCC, 0xCC, 0x33, 0x33, 0xCC, 0xCC, 0x33, 0x33};
  192.  
  193. static XFontStruct  fontInfo;
  194. static Nlm_Uint1    flip [256];
  195.  
  196. static Nlm_Boolean  hasColor;
  197. static Nlm_RgnTool  emptyRgn;
  198. #endif
  199.  
  200. #ifdef WIN_MAC
  201. extern  void  Nlm_SetPort (GrafPtr grafptr)
  202.  
  203. {
  204.   SetPort (grafptr);
  205. }
  206. #endif
  207.  
  208. #ifdef WIN_MSWIN
  209. extern  void  Nlm_SetPort (HWND hwnd, HDC hdc)
  210.  
  211. {
  212.   Nlm_currentHWnd = hwnd;
  213.   Nlm_currentHDC = hdc;
  214. }
  215. #endif
  216.  
  217. #ifdef WIN_X
  218. extern  void  Nlm_SetPort (Window window, GC gc)
  219.  
  220. {
  221.   Nlm_currentXWindow = window;
  222.   Nlm_currentXGC = gc;
  223. }
  224.  
  225. /* for internal Vibrant use only */
  226. extern  XFontStruct * Nlm_XLoadQueryFont (Display *d, Nlm_CharPtr fDescr, Nlm_Boolean critical)
  227. {
  228.   XFontStruct *f;
  229.  
  230.   if ((f = XLoadQueryFont(d, fDescr)) == NULL && critical)
  231.   {
  232.     fprintf (stderr, "Vibrant: Unable to load critical font <%s>\n", fDescr);
  233.     exit (1);
  234.   }
  235.  
  236.   return f;
  237. }
  238.  
  239. #endif
  240.  
  241. static void Nlm_LoadFontData (Nlm_FonT f, Nlm_FonT nxt,
  242.                               Nlm_CharPtr nam, Nlm_Int2 siz,
  243.                               Nlm_Int2 scl, Nlm_Boolean bld,
  244.                               Nlm_Boolean itl, Nlm_Boolean und,
  245.                               Nlm_Int2 num, Nlm_Int2 stl,
  246.                               Nlm_FontTool hdl, Nlm_FonT prnt)
  247.  
  248. {
  249.   Nlm_FntPtr  fp;
  250.  
  251.   if (f != NULL) {
  252.     fp = (Nlm_FntPtr) Nlm_HandLock (f);
  253.     fp->next = nxt;
  254.     Nlm_StringNCpy (fp->name, nam, sizeof (fp->name));
  255.     fp->size = siz;
  256.     fp->scale = scl;
  257.     fp->bld = bld;
  258.     fp->ital = itl;
  259.     fp->undlin = und;
  260.     fp->number = num;
  261.     fp->style = stl;
  262.     fp->handle = hdl;
  263.     fp->print = prnt;
  264.     Nlm_HandUnlock (f);
  265.   }
  266. }
  267.  
  268. static void Nlm_SetFontData (Nlm_FonT f, Nlm_FontData * fdata)
  269.  
  270. {
  271.   Nlm_FntPtr  fp;
  272.  
  273.   if (f != NULL && fdata != NULL) {
  274.     fp = (Nlm_FntPtr) Nlm_HandLock (f);
  275.     *fp = *fdata;
  276.     Nlm_HandUnlock (f);
  277.   }
  278. }
  279.  
  280. #ifdef DCLAP
  281. extern
  282. #else 
  283. static
  284. #endif
  285.  void Nlm_GetFontData (Nlm_FonT f, Nlm_FontData * fdata)
  286.  
  287. {
  288.   Nlm_FntPtr  fp;
  289.  
  290.   if (f != NULL && fdata != NULL) {
  291.     fp = (Nlm_FntPtr) Nlm_HandLock (f);
  292.     *fdata = *fp;
  293.     Nlm_HandUnlock (f);
  294.   }
  295. }
  296.  
  297. #ifdef WIN_MAC
  298. static void Nlm_ChooseColor (Nlm_Int4 color)
  299.  
  300. {
  301.   ForeColor (color);
  302. }
  303.  
  304. #endif
  305.  
  306. #ifdef WIN_MSWIN
  307. static Nlm_Boolean Nlm_NotAStockPen (HPEN pen)
  308.  
  309. {
  310.   return (Nlm_Boolean) (pen != hBlackPen && pen != hNullPen && pen != hWhitePen);
  311. }
  312.  
  313. static Nlm_Boolean Nlm_NotAStockBrush (HBRUSH brush)
  314.  
  315. {
  316.   return (Nlm_Boolean) (brush != hBlackBrush && brush != hDkGrayBrush &&
  317.                         brush != hGrayBrush && brush != hHollowBrush &&
  318.                         brush != hLtGrayBrush && hNullBrush &&
  319.                         brush != hWhiteBrush);
  320. }
  321.  
  322. static Nlm_Boolean Nlm_NotAStockFont (HFONT font)
  323.  
  324. {
  325.   return (Nlm_Boolean) (font != hAnsiFixedFont && font != hAnsiVarFont &&
  326.                         font != hDeviceDefaultFont && font != hOemFixedFont &&
  327.                         font != hSystemFont && font != hSystemFixedFont);
  328. }
  329.  
  330. static void Nlm_RecreateBrushes (void)
  331.  
  332. {
  333.   Nlm_Int4  color;
  334.   HBITMAP   hBitmap;
  335.   HBRUSH    newBrush;
  336.   HPEN      newPen;
  337.   HBRUSH    oldBrush;
  338.   HPEN      oldPen;
  339.  
  340.   if (Nlm_currentHDC != NULL) {
  341.     color = GetTextColor (Nlm_currentHDC);
  342.     newPen = CreatePen (currentPenStyle, currentPenWidth, color);
  343.     if (newPen != NULL) {
  344.       oldPen = SelectObject (Nlm_currentHDC, newPen);
  345.       if (Nlm_NotAStockPen (oldPen)) {
  346.         DeleteObject (oldPen);
  347.       }
  348.     }
  349.     if (currentPattern == NULL) {
  350.       currentPattern = whitePat;
  351.     }
  352.     hBitmap = CreateBitmap (8, 8, 1, 1, (LPSTR) currentPattern);
  353.     newBrush = CreatePatternBrush (hBitmap);
  354.     if (newBrush != NULL) {
  355.       oldBrush = SelectObject (Nlm_currentHDC, newBrush);
  356.       if (Nlm_NotAStockBrush (oldBrush)) {
  357.         DeleteObject (oldBrush);
  358.       }
  359.     }
  360.     DeleteObject (hBitmap);
  361.   }
  362. }
  363.  
  364. static void Nlm_SelectPattern (Nlm_Int2 style, Nlm_Int2 width, void * pat)
  365.  
  366. {
  367.   currentPenStyle = style;
  368.   currentPenWidth = width;
  369.   currentPattern = pat;
  370.   Nlm_RecreateBrushes ();
  371. }
  372.  
  373.  
  374.  
  375. static void Nlm_ChooseColor (Nlm_Int4 color)
  376.  
  377. {
  378.   if (Nlm_currentHDC != NULL) {
  379.     SetTextColor (Nlm_currentHDC, color);
  380.     Nlm_RecreateBrushes ();
  381.   }
  382. }
  383.  
  384. static Nlm_Boolean Nlm_GetTextMetrics (void)
  385.  
  386. {
  387.   HDC          hDC;
  388.   Nlm_Boolean  success;
  389.  
  390.   success = FALSE;
  391.   if (Nlm_currentHDC != NULL) {
  392.     success = (Nlm_Boolean) GetTextMetrics (Nlm_currentHDC, &textMetrics);
  393.   } else {
  394.     hDC = CreateIC ("DISPLAY", NULL, NULL, NULL);
  395.     success = (Nlm_Boolean) GetTextMetrics (hDC, &textMetrics);
  396.     DeleteDC (hDC);
  397.   }
  398.   return success;
  399. }
  400.  
  401. static HBRUSH GetBackgroundBrush (HWND hwnd)
  402.  
  403. {
  404. #if !defined(WIN32) && !defined(WIN32BOR)
  405.   return (HBRUSH) GetClassWord (hwnd, GCW_HBRBACKGROUND);
  406. #else
  407.   return (HBRUSH) GetClassLong (hwnd, GCL_HBRBACKGROUND);
  408. #endif
  409. }
  410. #endif
  411.  
  412. #ifdef WIN_X
  413. static void Nlm_SelectPattern (void * pat)
  414.  
  415. {
  416.   if (Nlm_currentXDisplay != NULL && Nlm_currentXWindow != 0) {
  417.     if (currentPixmap != 0) {
  418.       XFreePixmap (Nlm_currentXDisplay, currentPixmap);
  419.     }
  420.     currentPixmap = XCreateBitmapFromData (Nlm_currentXDisplay, Nlm_currentXWindow,
  421.                                            (char *) pat, 8, 8);
  422.     if (currentPixmap != 0 && Nlm_currentXGC != NULL) {
  423.       XSetStipple (Nlm_currentXDisplay, Nlm_currentXGC, currentPixmap);
  424.     }
  425.   }
  426. }
  427.  
  428. static void Nlm_ChooseColor (Nlm_Uint4 color)
  429.  
  430. {
  431.   if (Nlm_currentXDisplay != NULL && Nlm_currentXGC != NULL) {
  432.     XSetForeground (Nlm_currentXDisplay, Nlm_currentXGC, color);
  433.     currentFgColor = color;
  434.   }
  435. }
  436.  
  437. static Nlm_Boolean Nlm_GetTextMetrics (void)
  438.  
  439. {
  440.   Nlm_Boolean  success;
  441.  
  442.   success = FALSE;
  443.   if (Nlm_currentXDisplay != NULL && Nlm_currentXGC != NULL) {
  444.     if (currentFont != NULL) {
  445.       fontInfo = *currentFont;
  446.       success = TRUE;
  447.     }
  448.   }
  449.   return success;
  450. }
  451. #endif
  452.  
  453.  
  454. #ifdef DCLAP
  455.  
  456. extern void Nlm_SetBackColor (Nlm_Uint4 color)
  457. {
  458. #ifdef WIN_MAC
  459.   Nlm_Uint2  bl;
  460.   Nlm_Uint2  gn;
  461.   Nlm_Uint2  rd;
  462.   Nlm_Uint1  colors [4];
  463.   RGBColor   foreColor;
  464.   GrafPtr    port;
  465.  
  466.   if (hasColorQD) {
  467.     *((Nlm_Int4Ptr) colors) = color;
  468.     rd = (Nlm_Uint2) colors [1];
  469.     gn = (Nlm_Uint2) colors [2];
  470.     bl = (Nlm_Uint2) colors [3];
  471.     foreColor.red = rd << 8;
  472.     foreColor.green = gn << 8;
  473.     foreColor.blue = bl << 8;
  474.     RGBBackColor (&foreColor);
  475.   } else {
  476.     GetPort (&port);
  477.     if (port != NULL) {
  478.       BackColor ((Nlm_Int4) color);
  479.     }
  480.   }
  481. #endif
  482. #ifdef WIN_MSWIN
  483.   if (Nlm_currentHDC != NULL) {
  484.     SetBkColor (Nlm_currentHDC, color);
  485.     Nlm_RecreateBrushes ();
  486.       }
  487. #endif
  488.  
  489. #ifdef WIN_X
  490.     currentBkColor = color;
  491.     XSetBackground (Nlm_currentXDisplay, Nlm_currentXGC, currentBkColor);
  492. #endif
  493. }
  494.  
  495. extern void Nlm_SelectBackColor (Nlm_Uint1 red, Nlm_Uint1 green, Nlm_Uint1 blue)
  496. {
  497. #ifdef WIN_MAC
  498.   RGBColor   color;
  499.   Nlm_Uint2  bl;
  500.   Nlm_Uint2  gn;
  501.   Nlm_Uint2  rd;
  502.  
  503.   if (hasColorQD) {
  504.     rd = (Nlm_Uint2) red;
  505.     gn = (Nlm_Uint2) green;
  506.     bl = (Nlm_Uint2) blue;
  507.     color.red = rd << 8;
  508.     color.green = gn << 8;
  509.     color.blue = bl << 8;
  510.     RGBBackColor (&color);
  511.       } 
  512.   else if ((int) red + (int) green + (int) blue < 192)  
  513.       BackColor (blackColor);
  514.   else  
  515.       BackColor (whiteColor);
  516.           
  517. #endif
  518. #ifdef WIN_MSWIN
  519.   COLORREF   color;
  520.   Nlm_Uint2  bl;
  521.   Nlm_Uint2  gn;
  522.   Nlm_Uint2  rd;
  523.  
  524.   rd = (Nlm_Uint2) red;
  525.   gn = (Nlm_Uint2) green;
  526.   bl = (Nlm_Uint2) blue;
  527.   color = RGB (rd, gn, bl);
  528.   if (Nlm_currentHDC != NULL) {
  529.     SetBkColor (Nlm_currentHDC, color);
  530.     Nlm_RecreateBrushes ();
  531.       }
  532. #endif
  533. #ifdef WIN_X
  534.   Colormap   colormap;
  535.   Nlm_Uint2  bl;
  536.   Nlm_Uint2  gn;
  537.   Nlm_Uint2  rd;
  538.   XColor     xcolor;
  539.  
  540.   if (Nlm_currentXDisplay == NULL || Nlm_currentXGC == NULL) 
  541.       return;
  542.   else if (hasColor) {
  543.     rd = (Nlm_Uint2) red;
  544.     gn = (Nlm_Uint2) green;
  545.     bl = (Nlm_Uint2) blue;
  546.     xcolor.red = rd << 8;
  547.     xcolor.green = gn << 8;
  548.     xcolor.blue = bl << 8;
  549.     if (Nlm_currentXDisplay != NULL) {
  550.       colormap = DefaultColormap (Nlm_currentXDisplay, Nlm_currentXScreen);
  551.       if (XAllocColor (Nlm_currentXDisplay, colormap, &xcolor) == 0) 
  552.         xcolor.pixel = WhitePixel (Nlm_currentXDisplay, Nlm_currentXScreen);
  553.         currentBkColor = xcolor.pixel;
  554.         }
  555.       } 
  556.   else if ((int) red + (int) green + (int) blue < 192) 
  557.     currentBkColor = blackColor;
  558.   else 
  559.     currentBkColor = whiteColor;
  560.     XSetBackground (Nlm_currentXDisplay, Nlm_currentXGC, currentBkColor);
  561. #endif
  562. }
  563.  
  564. #endif /* DCLAP */
  565.  
  566.  
  567.  
  568. extern void Nlm_ResetDrawingTools (void)
  569.  
  570. {
  571. #ifdef WIN_MAC
  572.   PenNormal ();
  573.   PenMode (patCopy);
  574.   TextMode (srcOr);
  575.   if (hasColorQD) {
  576.     RGBForeColor (&Nlm_RGBforeColor);
  577.     RGBBackColor (&Nlm_RGBbackColor);
  578.   } else {
  579.     ForeColor (blackColor);
  580.     BackColor (whiteColor);
  581.   }
  582. #endif
  583. #ifdef WIN_MSWIN
  584.   HBRUSH  oldBrush;
  585.   HFONT   oldFont;
  586.   HPEN    oldPen;
  587.  
  588.   if (Nlm_currentHDC != NULL) {
  589.     SetROP2 (Nlm_currentHDC, R2_COPYPEN);
  590.     oldPen = SelectObject (Nlm_currentHDC, GetStockObject (BLACK_PEN));
  591.     oldBrush = SelectObject (Nlm_currentHDC, GetStockObject (BLACK_BRUSH));
  592.     oldFont = SelectObject (Nlm_currentHDC, GetStockObject (SYSTEM_FONT));
  593.     SetTextColor (Nlm_currentHDC, GetSysColor (COLOR_WINDOWTEXT));
  594.     SetBkColor (Nlm_currentHDC, GetSysColor (COLOR_WINDOW));
  595.     if (Nlm_NotAStockPen (oldPen)) {
  596.       DeleteObject (oldPen);
  597.     }
  598.     if (Nlm_NotAStockBrush (oldBrush)) {
  599.       DeleteObject (oldBrush);
  600.     }
  601.     Nlm_SelectPattern (PS_SOLID, 1, blackPat);
  602.   }
  603. #endif
  604. #ifdef WIN_X
  605.   if (Nlm_currentXDisplay != NULL && Nlm_currentXGC != NULL) {
  606.     currentMode = COPY_MODE;
  607.     currentFunction = GXcopy;
  608.     currentFillStyle = FillOpaqueStippled;
  609.     XSetFunction (Nlm_currentXDisplay, Nlm_currentXGC, currentFunction);
  610.     XSetFillStyle (Nlm_currentXDisplay, Nlm_currentXGC, currentFillStyle);
  611.     if (hasColor) {
  612.       XSetBackground (Nlm_currentXDisplay, Nlm_currentXGC, Nlm_XbackColor);
  613.       XSetForeground (Nlm_currentXDisplay, Nlm_currentXGC, Nlm_XforeColor);
  614.       currentBkColor = Nlm_XbackColor;
  615.       currentFgColor = Nlm_XforeColor;
  616.     } else {
  617.       XSetBackground (Nlm_currentXDisplay, Nlm_currentXGC, whiteColor);
  618.       XSetForeground (Nlm_currentXDisplay, Nlm_currentXGC, blackColor);
  619.       currentBkColor = whiteColor;
  620.       currentFgColor = blackColor;
  621.     }
  622.     XSetLineAttributes (Nlm_currentXDisplay, Nlm_currentXGC,
  623.                         1, LineSolid, CapButt, JoinMiter);
  624.     Nlm_SelectPattern (blackPat);
  625.   }
  626. #endif
  627.   currentMode = COPY_MODE;
  628. }
  629.  
  630. static void Nlm_PointToolToPoinT (Nlm_PointTool src, Nlm_PointPtr dst)
  631.  
  632. {
  633.   if (dst != NULL) {
  634. #ifdef WIN_MAC
  635.     dst->x = src.h;
  636.     dst->y = src.v;
  637. #endif
  638. #ifdef WIN_MSWIN
  639.     dst->x = (Nlm_IntD) src.x;
  640.     dst->y = (Nlm_IntD) src.y;
  641. #endif
  642. #ifdef WIN_X
  643.     dst->x = src.x;
  644.     dst->y = src.y;
  645. #endif
  646.   }
  647. }
  648.  
  649. static void Nlm_PoinTToPointTool (Nlm_PoinT src, Nlm_PointTool PNTR dst)
  650.  
  651. {
  652.   if (dst != NULL) {
  653. #ifdef WIN_MAC
  654.     dst->h = src.x;
  655.     dst->v = src.y;
  656. #endif
  657. #ifdef WIN_MSWIN
  658.     dst->x = src.x;
  659.     dst->y = src.y;
  660. #endif
  661. #ifdef WIN_X
  662.     dst->x = src.x;
  663.     dst->y = src.y;
  664. #endif
  665.   }
  666. }
  667.  
  668. static void Nlm_RectToolToRecT (Nlm_RectTool PNTR src, Nlm_RectPtr dst)
  669.  
  670. {
  671.   if (dst != NULL && src != NULL) {
  672. #ifdef WIN_MAC
  673.     dst->left = src->left;
  674.     dst->top = src->top;
  675.     dst->right = src->right;
  676.     dst->bottom = src->bottom;
  677. #endif
  678. #ifdef WIN_MSWIN
  679.     dst->left = (Nlm_IntD) src->left;
  680.     dst->top = (Nlm_IntD) src->top;
  681.     dst->right = (Nlm_IntD) src->right;
  682.     dst->bottom = (Nlm_IntD) src->bottom;
  683. #endif
  684. #ifdef WIN_X
  685.     dst->left = src->x;
  686.     dst->top = src->y;
  687.     dst->right = src->x + src->width;
  688.     dst->bottom = src->y + src->height;
  689. #endif
  690.   }
  691. }
  692.  
  693. static void Nlm_RecTToRectTool (Nlm_RectPtr src, Nlm_RectTool PNTR dst)
  694.  
  695. {
  696.   if (dst != NULL && src != NULL) {
  697. #ifdef WIN_MAC
  698.     dst->left = MIN (src->left, src->right);
  699.     dst->top = MIN (src->top, src->bottom);
  700.     dst->right = MAX (src->left, src->right);
  701.     dst->bottom = MAX (src->top, src->bottom);
  702. #endif
  703. #ifdef WIN_MSWIN
  704.     dst->left = MIN (src->left, src->right);
  705.     dst->top = MIN (src->top, src->bottom);
  706.     dst->right = MAX (src->left, src->right);
  707.     dst->bottom = MAX (src->top, src->bottom);
  708. #endif
  709. #ifdef WIN_X
  710.     dst->x = MIN (src->left, src->right);
  711.     dst->y = MIN (src->top, src->bottom);
  712.     dst->width = ABS (src->right - src->left);
  713.     dst->height = ABS (src->bottom - src->top);
  714. #endif
  715.   }
  716. }
  717.  
  718. static void Nlm_LocalToGlobal (Nlm_PointPtr pt)
  719.  
  720. {
  721. #ifdef WIN_MAC
  722.   Nlm_PointTool  ptool;
  723.  
  724.   if (pt != NULL) {
  725.     Nlm_PoinTToPointTool (*pt, &ptool);
  726.     LocalToGlobal (&ptool);
  727.     Nlm_PointToolToPoinT (ptool, pt);
  728.   }
  729. #endif
  730. #ifdef WIN_MSWIN
  731.   Nlm_PointTool  ptool;
  732.  
  733.   if (pt != NULL && Nlm_currentHWnd != NULL) {
  734.     Nlm_PoinTToPointTool (*pt, &ptool);
  735.     ClientToScreen (Nlm_currentHWnd, &ptool);
  736.     Nlm_PointToolToPoinT (ptool, pt);
  737.   }
  738. #endif
  739. #ifdef WIN_X
  740. #endif
  741. }
  742.  
  743. static void Nlm_GlobalToLocal (Nlm_PointPtr pt)
  744.  
  745. {
  746. #ifdef WIN_MAC
  747.   Nlm_PointTool  ptool;
  748.  
  749.   if (pt != NULL) {
  750.     Nlm_PoinTToPointTool (*pt, &ptool);
  751.     GlobalToLocal (&ptool);
  752.     Nlm_PointToolToPoinT (ptool, pt);
  753.   }
  754. #endif
  755. #ifdef WIN_MSWIN
  756.   Nlm_PointTool  ptool;
  757.  
  758.   if (pt != NULL && Nlm_currentHWnd != NULL) {
  759.     Nlm_PoinTToPointTool (*pt, &ptool);
  760.     ScreenToClient (Nlm_currentHWnd, &ptool);
  761.     Nlm_PointToolToPoinT (ptool, pt);
  762.   }
  763. #endif
  764. #ifdef WIN_X
  765. #endif
  766. }
  767.  
  768. #ifdef OS_MAC
  769. static void Nlm_CtoPstr (Nlm_CharPtr str)
  770.  
  771. {
  772. #if defined(COMP_MPW) || defined(COMP_CODEWAR)
  773.     c2pstr ((char *) str);
  774. #else
  775. #ifdef COMP_THINKC
  776.     CtoPstr ((char *) str);
  777. #endif
  778. #endif
  779. }
  780.  
  781. static void Nlm_PtoCstr (Nlm_CharPtr str)
  782.  
  783. {
  784. #if defined(COMP_MPW) || defined(COMP_CODEWAR)
  785.   p2cstr ((StringPtr) str);
  786. #else
  787. #ifdef COMP_THINKC
  788.   PtoCstr ((StringPtr) str);
  789. #endif
  790. #endif
  791. }
  792. #endif
  793.  
  794. extern void Nlm_CopyMode (void)
  795.  
  796. {
  797. #ifdef WIN_MAC
  798.   PenMode (patCopy);
  799. #ifdef DCLAP
  800.   TextMode (srcCopy);
  801. #else
  802.   TextMode (srcOr);
  803. #endif
  804. #endif
  805. #ifdef WIN_MSWIN
  806.   if (Nlm_currentHDC != NULL) {
  807.     SetROP2 (Nlm_currentHDC, R2_COPYPEN);
  808.   }
  809. #endif
  810. #ifdef WIN_X
  811.   currentFunction = GXcopy;
  812.   currentFillStyle = FillOpaqueStippled;
  813.   if (Nlm_currentXDisplay != NULL && Nlm_currentXGC != NULL) {
  814.     XSetFunction (Nlm_currentXDisplay, Nlm_currentXGC, currentFunction);
  815.     XSetFillStyle (Nlm_currentXDisplay, Nlm_currentXGC, currentFillStyle);
  816.   }
  817. #endif
  818.   currentMode = COPY_MODE;
  819. }
  820.  
  821. extern void Nlm_MergeMode (void)
  822.  
  823. {
  824. #ifdef WIN_MAC
  825.   PenMode (patOr);
  826.   TextMode (srcOr);
  827. #endif
  828. #ifdef WIN_MSWIN
  829.   if (Nlm_currentHDC != NULL) {
  830.     SetROP2 (Nlm_currentHDC, R2_MASKPEN);
  831.   }
  832. #endif
  833. #ifdef WIN_X
  834.   if (hasColor) {
  835.     currentFunction = GXand;
  836.   } else {
  837.     currentFunction = GXor;
  838.   }
  839.   currentFillStyle = FillStippled;
  840.   if (Nlm_currentXDisplay != NULL && Nlm_currentXGC != NULL) {
  841.     XSetFunction (Nlm_currentXDisplay, Nlm_currentXGC, currentFunction);
  842.     XSetFillStyle (Nlm_currentXDisplay, Nlm_currentXGC, currentFillStyle);
  843.   }
  844. #endif
  845.   currentMode = MERGE_MODE;
  846. }
  847.  
  848. extern void Nlm_InvertMode (void)
  849.  
  850. {
  851. #ifdef WIN_MAC
  852.   PenMode (patXor);
  853.   TextMode (srcXor);
  854. #endif
  855. #ifdef WIN_MSWIN
  856.   if (Nlm_currentHDC != NULL) {
  857.     SetROP2 (Nlm_currentHDC, R2_NOTXORPEN);
  858.   }
  859. #endif
  860. #ifdef WIN_X
  861. #ifndef no_DCLAP
  862.   if (hasColor) {
  863.     currentFunction = GXequiv;
  864.   } else
  865. #endif 
  866.   {
  867.     currentFunction = GXinvert;
  868.   }
  869.   currentFillStyle = FillStippled;
  870.   if (Nlm_currentXDisplay != NULL && Nlm_currentXGC != NULL) {
  871.     XSetFunction (Nlm_currentXDisplay, Nlm_currentXGC, currentFunction);
  872.     XSetFillStyle (Nlm_currentXDisplay, Nlm_currentXGC, currentFillStyle);
  873.   }
  874. #endif
  875.   currentMode = INVERT_MODE;
  876. }
  877.  
  878. extern void Nlm_EraseMode (void)
  879.  
  880.  
  881. {
  882. #ifdef WIN_MAC
  883.   PenMode (patBic);
  884.   TextMode (srcBic);
  885. #endif
  886. #ifdef WIN_MSWIN
  887.   if (Nlm_currentHDC != NULL) {
  888.     SetROP2 (Nlm_currentHDC, R2_MERGENOTPEN);
  889.   }
  890. #endif
  891. #ifdef WIN_X
  892.   if (hasColor) {
  893.     currentFunction = GXorInverted;
  894.   } else {
  895.     currentFunction = GXand;
  896.   }
  897.   currentFillStyle = FillStippled;
  898.   if (Nlm_currentXDisplay != NULL && Nlm_currentXGC != NULL) {
  899.     XSetFunction (Nlm_currentXDisplay, Nlm_currentXGC, currentFunction);
  900.     XSetFillStyle (Nlm_currentXDisplay, Nlm_currentXGC, currentFillStyle);
  901.   }
  902. #endif
  903.   currentMode = ERASE_MODE;
  904. }
  905.  
  906. extern void Nlm_Black (void)
  907.  
  908. {
  909. #ifdef WIN_MAC
  910.   if (hasColorQD) {
  911.     Nlm_SelectColor (0, 0, 0);
  912.   } else {
  913.     Nlm_ChooseColor (blackColor);
  914.   }
  915. #endif
  916. #ifdef WIN_MSWIN
  917.   Nlm_ChooseColor (blackColor);
  918. #endif
  919. #ifdef WIN_X
  920.   Nlm_ChooseColor (blackColor);
  921. #endif
  922. }
  923.  
  924. extern void Nlm_Red (void)
  925.  
  926. {
  927. #ifdef WIN_MAC
  928.   if (hasColorQD) {
  929.     Nlm_SelectColor (255, 0, 0);
  930.   } else {
  931.     Nlm_ChooseColor (redColor);
  932.   }
  933. #endif
  934. #ifdef WIN_MSWIN
  935.   Nlm_ChooseColor (redColor);
  936. #endif
  937. #ifdef WIN_X
  938.   Nlm_ChooseColor (redColor);
  939. #endif
  940. }
  941.  
  942. extern void Nlm_Green (void)
  943.  
  944. {
  945. #ifdef WIN_MAC
  946.   if (hasColorQD) {
  947.     Nlm_SelectColor (0, 255, 0);
  948.   } else {
  949.     Nlm_ChooseColor (greenColor);
  950.   }
  951. #endif
  952. #ifdef WIN_MSWIN
  953.   Nlm_ChooseColor (greenColor);
  954. #endif
  955. #ifdef WIN_X
  956.   Nlm_ChooseColor (greenColor);
  957. #endif
  958. }
  959.  
  960. extern void Nlm_Blue (void)
  961.  
  962. {
  963. #ifdef WIN_MAC
  964.   if (hasColorQD) {
  965.     Nlm_SelectColor (0, 0, 255);
  966.   } else {
  967.     Nlm_ChooseColor (blueColor);
  968.   }
  969. #endif
  970. #ifdef WIN_MSWIN
  971.   Nlm_ChooseColor (blueColor);
  972. #endif
  973. #ifdef WIN_X
  974.   Nlm_ChooseColor (blueColor);
  975. #endif
  976. }
  977.  
  978. extern void Nlm_Cyan (void)
  979.  
  980. {
  981. #ifdef WIN_MAC
  982.   if (hasColorQD) {
  983.     Nlm_SelectColor (0, 255, 255);
  984.   } else {
  985.     Nlm_ChooseColor (cyanColor);
  986.   }
  987. #endif
  988. #ifdef WIN_MSWIN
  989.   Nlm_ChooseColor (cyanColor);
  990. #endif
  991. #ifdef WIN_X
  992.   Nlm_ChooseColor (cyanColor);
  993. #endif
  994. }
  995.  
  996. extern void Nlm_Magenta (void)
  997.  
  998. {
  999. #ifdef WIN_MAC
  1000.   if (hasColorQD) {
  1001.     Nlm_SelectColor (255, 0, 255);
  1002.   } else {
  1003.     Nlm_ChooseColor (magentaColor);
  1004.   }
  1005. #endif
  1006. #ifdef WIN_MSWIN
  1007.   Nlm_ChooseColor (magentaColor);
  1008. #endif
  1009. #ifdef WIN_X
  1010.   Nlm_ChooseColor (magentaColor);
  1011. #endif
  1012. }
  1013.  
  1014. extern void Nlm_Yellow (void)
  1015.  
  1016. {
  1017. #ifdef WIN_MAC
  1018.   if (hasColorQD) {
  1019.     Nlm_SelectColor (255, 255, 0);
  1020.   } else {
  1021.     Nlm_ChooseColor (yellowColor);
  1022.   }
  1023. #endif
  1024. #ifdef WIN_MSWIN
  1025.   Nlm_ChooseColor (yellowColor);
  1026. #endif
  1027. #ifdef WIN_X
  1028.   Nlm_ChooseColor (yellowColor);
  1029. #endif
  1030. }
  1031.  
  1032. extern void Nlm_White (void)
  1033.  
  1034. {
  1035. #ifdef WIN_MAC
  1036.   if (hasColorQD) {
  1037.     Nlm_SelectColor (255, 255, 255);
  1038.   } else {
  1039.     Nlm_ChooseColor (whiteColor);
  1040.   }
  1041. #endif
  1042. #ifdef WIN_MSWIN
  1043.   Nlm_ChooseColor (whiteColor);
  1044. #endif
  1045. #ifdef WIN_X
  1046.   Nlm_ChooseColor (whiteColor);
  1047. #endif
  1048. }
  1049.  
  1050. extern void Nlm_Gray (void)
  1051.  
  1052. {
  1053.   Nlm_SelectColor (127, 127, 127);
  1054. }
  1055.  
  1056. extern void Nlm_LtGray (void)
  1057.  
  1058. {
  1059.   Nlm_SelectColor (191, 191, 191);
  1060. }
  1061.  
  1062. extern void Nlm_DkGray (void)
  1063.  
  1064. {
  1065.   Nlm_SelectColor (63, 63, 63);
  1066. }
  1067.  
  1068. extern void Nlm_SelectColor (Nlm_Uint1 red, Nlm_Uint1 green, Nlm_Uint1 blue)
  1069.  
  1070. {
  1071. #ifdef WIN_MAC
  1072.   RGBColor   color;
  1073.   Nlm_Uint2  bl;
  1074.   Nlm_Uint2  gn;
  1075.   Nlm_Uint2  rd;
  1076.  
  1077.   if (hasColorQD) {
  1078.     rd = (Nlm_Uint2) red;
  1079.     gn = (Nlm_Uint2) green;
  1080.     bl = (Nlm_Uint2) blue;
  1081.     color.red = rd << 8;
  1082.     color.green = gn << 8;
  1083.     color.blue = bl << 8;
  1084.     RGBForeColor (&color);
  1085.   } else if ((int) red + (int) green + (int) blue < 192) {
  1086.     Nlm_ChooseColor (blackColor);
  1087.   } else {
  1088.     Nlm_ChooseColor (whiteColor);
  1089.   }
  1090. #endif
  1091. #ifdef WIN_MSWIN
  1092.   COLORREF   color;
  1093.   Nlm_Uint2  bl;
  1094.   Nlm_Uint2  gn;
  1095.   Nlm_Uint2  rd;
  1096.  
  1097.   rd = (Nlm_Uint2) red;
  1098.   gn = (Nlm_Uint2) green;
  1099.   bl = (Nlm_Uint2) blue;
  1100.   color = RGB (rd, gn, bl);
  1101.   Nlm_ChooseColor (color);
  1102. #endif
  1103. #ifdef WIN_X
  1104.   Colormap   colormap;
  1105.   Nlm_Uint2  bl;
  1106.   Nlm_Uint2  gn;
  1107.   Nlm_Uint2  rd;
  1108.   XColor     xcolor;
  1109.  
  1110.   if (hasColor) {
  1111.     rd = (Nlm_Uint2) red;
  1112.     gn = (Nlm_Uint2) green;
  1113.     bl = (Nlm_Uint2) blue;
  1114.     xcolor.red = rd << 8;
  1115.     xcolor.green = gn << 8;
  1116.     xcolor.blue = bl << 8;
  1117.     if (Nlm_currentXDisplay != NULL) {
  1118.       colormap = DefaultColormap (Nlm_currentXDisplay, Nlm_currentXScreen);
  1119.       if (XAllocColor (Nlm_currentXDisplay, colormap, &xcolor) == 0) {
  1120.         xcolor.pixel = WhitePixel (Nlm_currentXDisplay, Nlm_currentXScreen);
  1121.       }
  1122.       Nlm_ChooseColor (xcolor.pixel);
  1123.     }
  1124.   } else if ((int) red + (int) green + (int) blue < 192) {
  1125.     Nlm_ChooseColor (blackColor);
  1126.   } else {
  1127.     Nlm_ChooseColor (whiteColor);
  1128.   }
  1129. #endif
  1130. }
  1131.  
  1132. extern Nlm_Uint4 Nlm_GetColor (void)
  1133.  
  1134. {
  1135. #ifdef WIN_MAC
  1136.   Nlm_Uint1  colors [4];
  1137.   RGBColor   foreColor;
  1138.   GrafPtr    port;
  1139.   Nlm_Int4   fgColor;
  1140.  
  1141.   fgColor = 0;
  1142.   if (hasColorQD) {
  1143.     GetForeColor (&foreColor);
  1144.     colors [0] = 0;
  1145.     colors [1] = (Nlm_Uint1) (foreColor.red >> 8);
  1146.     colors [2] = (Nlm_Uint1) (foreColor.green >> 8);
  1147.     colors [3] = (Nlm_Uint1) (foreColor.blue >> 8);
  1148.     fgColor = *((Nlm_Int4Ptr) colors);
  1149.   } else {
  1150.     GetPort (&port);
  1151.     if (port != NULL) {
  1152.       fgColor = port->fgColor;
  1153.     }
  1154.   }
  1155.   return (Nlm_Uint4) fgColor;
  1156. #endif
  1157. #ifdef WIN_MSWIN
  1158.   Nlm_Int4  fgColor;
  1159.  
  1160.   fgColor = 0;
  1161.   if (Nlm_currentHDC != NULL) {
  1162.     fgColor = GetTextColor (Nlm_currentHDC);
  1163.   }
  1164.   return (Nlm_Uint4) fgColor;
  1165. #endif
  1166. #ifdef WIN_X
  1167.   Nlm_Uint4  fgColor;
  1168.  
  1169.   fgColor = currentFgColor;
  1170.   return (Nlm_Uint4) fgColor;
  1171. #endif
  1172. }
  1173.  
  1174. extern void Nlm_SetColor (Nlm_Uint4 color)
  1175.  
  1176. {
  1177. #ifdef WIN_MAC
  1178.   Nlm_Uint2  bl;
  1179.   Nlm_Uint2  gn;
  1180.   Nlm_Uint2  rd;
  1181.   Nlm_Uint1  colors [4];
  1182.   RGBColor   foreColor;
  1183.   GrafPtr    port;
  1184.  
  1185.   if (hasColorQD) {
  1186.     *((Nlm_Int4Ptr) colors) = color;
  1187.     rd = (Nlm_Uint2) colors [1];
  1188.     gn = (Nlm_Uint2) colors [2];
  1189.     bl = (Nlm_Uint2) colors [3];
  1190.     foreColor.red = rd << 8;
  1191.     foreColor.green = gn << 8;
  1192.     foreColor.blue = bl << 8;
  1193.     RGBForeColor (&foreColor);
  1194.   } else {
  1195.     GetPort (&port);
  1196.     if (port != NULL) {
  1197.       ForeColor ((Nlm_Int4) color);
  1198.     }
  1199.   }
  1200. #endif
  1201. #ifdef WIN_MSWIN
  1202.   if (Nlm_currentHDC != NULL) {
  1203.     SetTextColor (Nlm_currentHDC, (Nlm_Int4) color);
  1204.     Nlm_RecreateBrushes ();
  1205.   }
  1206. #endif
  1207. #ifdef WIN_X
  1208.   XSetForeground (Nlm_currentXDisplay, Nlm_currentXGC, color);
  1209.   currentFgColor = color;
  1210. #endif
  1211. }
  1212.  
  1213. extern void Nlm_InvertColors (void)
  1214.  
  1215. {
  1216. #ifdef WIN_MAC
  1217.   RGBColor  backColor;
  1218.   RGBColor  foreColor;
  1219.   GrafPtr   port;
  1220.   Nlm_Int4  bkColor;
  1221.   Nlm_Int4  fgColor;
  1222.  
  1223.   if (hasColorQD) {
  1224.     GetForeColor (&foreColor);
  1225.     GetBackColor (&backColor);
  1226.     RGBForeColor (&backColor);
  1227.     RGBBackColor (&foreColor);
  1228.   } else {
  1229.     GetPort (&port);
  1230.     if (port != NULL) {
  1231.       fgColor = port->fgColor;
  1232.       bkColor = port->bkColor;
  1233.       ForeColor (bkColor);
  1234.       BackColor (fgColor);
  1235.     }
  1236.   }
  1237. #endif
  1238. #ifdef WIN_MSWIN
  1239.   Nlm_Int4  bkColor;
  1240.   Nlm_Int4  fgColor;
  1241.  
  1242.   if (Nlm_currentHDC != NULL) {
  1243.     fgColor = GetTextColor (Nlm_currentHDC);
  1244.     bkColor = GetBkColor (Nlm_currentHDC);
  1245.     SetTextColor (Nlm_currentHDC, bkColor);
  1246.     SetBkColor (Nlm_currentHDC, fgColor);
  1247.     Nlm_RecreateBrushes ();
  1248.   }
  1249. #endif
  1250. #ifdef WIN_X
  1251.   Nlm_Uint4  newBkColor;
  1252.   Nlm_Uint4  newFgColor;
  1253.  
  1254.   newBkColor = currentFgColor;
  1255.   newFgColor = currentBkColor;
  1256.   XSetBackground (Nlm_currentXDisplay, Nlm_currentXGC, newBkColor);
  1257.   XSetForeground (Nlm_currentXDisplay, Nlm_currentXGC, newFgColor);
  1258.   currentBkColor = newBkColor;
  1259.   currentFgColor = newFgColor;
  1260. #endif
  1261. }
  1262.  
  1263.  
  1264. #ifdef DCLAP
  1265. extern void Nlm_PenPattern(void *pat)
  1266. {
  1267. #ifdef WIN_MAC
  1268.   PenPat ((ConstPatternParam) pat); 
  1269. #endif
  1270. #ifdef WIN_MSWIN
  1271.   Nlm_SelectPattern (PS_SOLID, 1, pat);
  1272. #endif
  1273. #ifdef WIN_X
  1274.   Nlm_SelectPattern (pat);
  1275. #endif
  1276. }
  1277. #endif
  1278.  
  1279.  
  1280. extern void Nlm_Solid (void)
  1281.  
  1282. {
  1283. #ifdef WIN_MAC
  1284.   PenPat ((ConstPatternParam) blackPat); 
  1285. #endif
  1286. #ifdef WIN_MSWIN
  1287.   Nlm_SelectPattern (PS_SOLID, 1, blackPat);
  1288. #endif
  1289. #ifdef WIN_X
  1290.   XGCValues  values;
  1291.  
  1292.   Nlm_SelectPattern (blackPat);
  1293.   if (Nlm_currentXDisplay != NULL && Nlm_currentXGC != NULL) {
  1294.     values.line_style = LineSolid;
  1295.     XChangeGC (Nlm_currentXDisplay, Nlm_currentXGC, GCLineStyle, &values);
  1296.   }
  1297. #endif
  1298. }
  1299.  
  1300. extern void Nlm_Dark (void)
  1301.  
  1302. {
  1303. #ifdef WIN_MAC
  1304.   PenPat ((ConstPatternParam) dkGrayPat);
  1305. #endif
  1306. #ifdef WIN_MSWIN
  1307.   Nlm_SelectPattern (PS_SOLID, 1, dkGrayPat);
  1308. #endif
  1309. #ifdef WIN_X
  1310.   Nlm_SelectPattern (dkGrayPat);
  1311. #endif
  1312. }
  1313.  
  1314. extern void Nlm_Medium (void)
  1315.  
  1316. {
  1317. #ifdef WIN_MAC
  1318.   PenPat ((ConstPatternParam) grayPat);
  1319. #endif
  1320. #ifdef WIN_MSWIN
  1321.   Nlm_SelectPattern (PS_SOLID, 1, grayPat);
  1322. #endif
  1323. #ifdef WIN_X
  1324.   Nlm_SelectPattern (grayPat);
  1325. #endif
  1326. }
  1327.  
  1328. extern void Nlm_Light (void)
  1329.  
  1330. {
  1331. #ifdef WIN_MAC
  1332.   PenPat ((ConstPatternParam) ltGrayPat);
  1333. #endif
  1334. #ifdef WIN_MSWIN
  1335.   Nlm_SelectPattern (PS_SOLID, 1, ltGrayPat);
  1336. #endif
  1337. #ifdef WIN_X
  1338.   Nlm_SelectPattern (ltGrayPat);
  1339. #endif
  1340. }
  1341.  
  1342. extern void Nlm_Empty (void)
  1343.  
  1344.  
  1345. {
  1346. #ifdef WIN_MAC
  1347.   PenPat ((ConstPatternParam) whitePat);
  1348. #endif
  1349. #ifdef WIN_MSWIN
  1350.   Nlm_SelectPattern (PS_SOLID, 1, whitePat);
  1351. #endif
  1352. #ifdef WIN_X
  1353.   Nlm_SelectPattern (whitePat);
  1354. #endif
  1355. }
  1356.  
  1357. extern void Nlm_Dotted (void)
  1358.  
  1359. {
  1360. #ifdef WIN_MAC
  1361.   PenPat ((ConstPatternParam) dotPat);
  1362. #endif
  1363. #ifdef WIN_MSWIN
  1364.   Nlm_SelectPattern (PS_DOT, 1, dotPat);
  1365. #endif
  1366. #ifdef WIN_X
  1367.   XGCValues  values;
  1368.  
  1369.   if (Nlm_currentXDisplay != NULL && Nlm_currentXGC != NULL) {
  1370.     values.line_style = LineOnOffDash;
  1371.     XChangeGC (Nlm_currentXDisplay, Nlm_currentXGC, GCLineStyle, &values);
  1372.   }
  1373. #endif
  1374. }
  1375.  
  1376. extern void Nlm_Dashed (void)
  1377.  
  1378. {
  1379. #ifdef WIN_MAC
  1380.   PenPat ((ConstPatternParam) dashPat);
  1381. #endif
  1382. #ifdef WIN_MSWIN
  1383.   Nlm_SelectPattern (PS_DASH, 1, dashPat);
  1384. #endif
  1385. #ifdef WIN_X
  1386.   XGCValues  values;
  1387.  
  1388.   if (Nlm_currentXDisplay != NULL && Nlm_currentXGC != NULL) {
  1389.     values.line_style = LineOnOffDash;
  1390.     XChangeGC (Nlm_currentXDisplay, Nlm_currentXGC, GCLineStyle, &values);
  1391.   }
  1392. #endif
  1393. }
  1394.  
  1395. extern void Nlm_WidePen (Nlm_Int2 width)
  1396.  
  1397.  
  1398. {
  1399. #ifdef WIN_MAC
  1400.   PenPat ((ConstPatternParam) blackPat);
  1401.   PenSize (width, width);
  1402. #endif
  1403. #ifdef WIN_MSWIN
  1404.   Nlm_SelectPattern (PS_SOLID, width, blackPat);
  1405. #endif
  1406. #ifdef WIN_X
  1407.   XGCValues  values;
  1408.  
  1409.   if (Nlm_currentXDisplay != NULL && Nlm_currentXGC != NULL) {
  1410.     values.line_width = width;
  1411.     XChangeGC (Nlm_currentXDisplay, Nlm_currentXGC, GCLineWidth, &values);
  1412.   }
  1413. #endif
  1414. }
  1415.  
  1416. static Nlm_FonT Nlm_CreateNewFont (Nlm_CharPtr name, Nlm_Int2 size,
  1417.                                    Nlm_Boolean bld, Nlm_Boolean itlc,
  1418.                                    Nlm_Boolean undrln, Nlm_CharPtr fmly)
  1419.  
  1420. {
  1421.   Nlm_Byte      charSet;
  1422.   Nlm_FontTool  hdl;
  1423.   Nlm_Int2      num;
  1424.   Nlm_FonT      rsult;
  1425.   Nlm_Int2      scale;
  1426.   Nlm_Int2      styl;
  1427.   Nlm_Int2      weight;
  1428. #ifdef WIN_MAC
  1429.   Nlm_Char      temp [256];
  1430. #endif
  1431. #ifdef WIN_MSWIN
  1432.   BYTE          family;
  1433.   HDC           hDC;
  1434.   POINT         ptool;
  1435. #endif
  1436. #ifdef WIN_X
  1437.   Nlm_Char      ptsize [16];
  1438.   Nlm_Char      temp [256];
  1439. #endif
  1440.  
  1441.   rsult = (Nlm_FonT) Nlm_HandNew (sizeof (Nlm_FontRec));
  1442.   if (rsult != NULL) {
  1443.     scale = size;
  1444. #ifdef WIN_MAC
  1445.     hdl = NULL;
  1446.     num = 0;
  1447.     if (name != NULL) {
  1448.       Nlm_StringNCpy (temp, name, sizeof (temp));
  1449.       Nlm_CtoPstr (temp);
  1450.       GetFNum ((StringPtr) temp, &num);
  1451. #ifndef DCLAP
  1452.       if (num == 0 && fmly != NULL && fmly [0] != '\0') {
  1453.         if (Nlm_StringICmp (fmly, "Roman") == 0) {
  1454.           num = 0; /* chicago */
  1455.         } else if (Nlm_StringICmp (fmly, "Swiss") == 0) {
  1456.           num = 3; /* geneva */
  1457.         } else if (Nlm_StringICmp (fmly, "Modern") == 0) {
  1458.           num = 4; /* monaco */
  1459.         } else if (Nlm_StringICmp (fmly, "Script") == 0) {
  1460.           num = 0; /* chicago  */
  1461.         } else if (Nlm_StringICmp (fmly, "Decorative") == 0) {
  1462.           num = 0; /* chicago  */
  1463.         }
  1464.       }
  1465. #endif
  1466.     }
  1467. #ifdef DCLAP
  1468.     if (num == 0 && fmly != NULL && fmly [0] != '\0') {
  1469.       if (Nlm_StringICmp (fmly, "Roman") == 0)  
  1470.           num = 20; /* times roman */
  1471.       else if (Nlm_StringICmp (fmly, "Swiss") == 0) 
  1472.           num = 21; /* helvetica */
  1473.       else if (Nlm_StringICmp (fmly, "Modern") == 0) 
  1474.           num = 22;  /* courier */
  1475.       else if (Nlm_StringICmp (fmly, "Script") == 0) 
  1476.           num = 20;     /* 18 == Zapf Chancery, !? or times */
  1477.       else if (Nlm_StringICmp (fmly, "Decorative") == 0) 
  1478.           num = 20; /* times roman */
  1479.       else
  1480.                num = 3; /* geneva == builtin == appl font */           
  1481.       }
  1482. #endif
  1483.    
  1484.     styl = 0;
  1485.     if (bld) {
  1486.       styl += bold;
  1487.     }
  1488.     if (itlc) {
  1489.       styl += italic;
  1490.     }
  1491.     if (undrln) {
  1492.       styl += underline;
  1493.     }
  1494. #endif
  1495. #ifdef WIN_MSWIN
  1496.     hdl = NULL;
  1497.     num = 0;
  1498.     styl = 0;
  1499.     if (bld) {
  1500.       weight = FW_BOLD;
  1501.     } else {
  1502.       weight = FW_NORMAL;
  1503.     }
  1504.     if (Nlm_StringICmp (name, "Symbol") == 0) {
  1505.       charSet = SYMBOL_CHARSET;
  1506.     } else if (Nlm_StringICmp (name, "Terminal") == 0) {
  1507.       charSet = OEM_CHARSET;
  1508.     } else {
  1509.       charSet = ANSI_CHARSET;
  1510.     }
  1511.     family = FF_DONTCARE;
  1512.     if (fmly != NULL && fmly [0] != '\0') {
  1513.       if (Nlm_StringICmp (fmly, "Roman") == 0) {
  1514.         family = FF_ROMAN;
  1515.       } else if (Nlm_StringICmp (fmly, "Swiss") == 0) {
  1516.         family = FF_SWISS;
  1517.       } else if (Nlm_StringICmp (fmly, "Modern") == 0) {
  1518.         family = FF_MODERN;
  1519.       } else if (Nlm_StringICmp (fmly, "Script") == 0) {
  1520.         family = FF_SCRIPT;
  1521.       } else if (Nlm_StringICmp (fmly, "Decorative") == 0) {
  1522.         family = FF_DECORATIVE;
  1523.       }
  1524.     }
  1525.     hDC = CreateCompatibleDC (NULL);
  1526.     SetMapMode (hDC, MM_ANISOTROPIC);
  1527.     SetWindowExtEx (hDC, 1440, 1440, NULL);
  1528.     SetViewportExtEx (hDC, GetDeviceCaps (hDC, LOGPIXELSX),
  1529.                       GetDeviceCaps (hDC, LOGPIXELSY), NULL);
  1530. #ifdef DCLAP
  1531.         DeleteDC (hDC);
  1532.         hdl = CreateFont (-size, 0, 0, 0, weight, itlc, undrln, FALSE,
  1533.                                             charSet, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS,
  1534.                                             DEFAULT_QUALITY, (BYTE) (DEFAULT_PITCH | family), name);
  1535. #else
  1536.         ptool.x = 0;
  1537.     ptool.y = 20 * size;
  1538.     LPtoDP (hDC, &ptool, 1);
  1539.     DeleteDC (hDC);
  1540.     scale = (Nlm_Int2) ptool.y;
  1541.     hdl = CreateFont (scale, 0, 0, 0, weight, itlc, undrln, FALSE,
  1542.                       charSet, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS,
  1543.                       DEFAULT_QUALITY, (BYTE) (DEFAULT_PITCH | family), name);
  1544.     /*
  1545.     hdl = CreateFont (-size, 0, 0, 0, weight, itlc, undrln, FALSE,
  1546.                       charSet, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS,
  1547.                       DEFAULT_QUALITY, (BYTE) (DEFAULT_PITCH | family), name);
  1548.     */
  1549. #endif
  1550.  
  1551. #endif
  1552. #ifdef WIN_X
  1553.     num = 0;
  1554.     styl = 0;
  1555.     hdl = NULL;
  1556.     if (name != NULL && Nlm_currentXDisplay != NULL) {
  1557.       StringCpy (temp, "-*-");
  1558.       StringCat (temp, name);
  1559.       StringCat (temp, "-");
  1560.             /* dgg ! some use "demi" and "light" ! */
  1561.       if (bld) {
  1562.         StringCat (temp, "bold-");
  1563.       } else {
  1564.         StringCat (temp, "medium-");
  1565.       }
  1566.             /* dgg ! some use "o", some use "i" for italic !! */
  1567.       if (itlc) {
  1568.         StringCat (temp, "o-");
  1569.       } else {
  1570.         StringCat (temp, "r-");
  1571.       }
  1572.       StringCat (temp, "*--");
  1573.       sprintf (ptsize, "%d", (int) size);
  1574.       StringCat (temp, ptsize);
  1575.       StringCat (temp, "-*");
  1576.       hdl = Nlm_XLoadQueryFont (Nlm_currentXDisplay, temp, FALSE);
  1577.       if (hdl == NULL) {
  1578.  
  1579. #ifdef DCLAP
  1580.                 int    size2, ipoints, ipixels;
  1581.                 char *sbold, *sitalic;
  1582.  
  1583.                 /* try scalable font ! */
  1584.                 if (itlc) sitalic= "i"; else sitalic= "r";   /* or "o" and "r" */
  1585.                 if (bld) sbold= "bold"; else sbold= "medium"; /* or "demi" and "light" */
  1586.                 ipoints= 0;    /* to select scalable font */
  1587.                 ipixels= size * 10; /* ?? */
  1588.               sprintf(temp, "-*-%s-%s-%s-*--%d-%d-*",name,sbold,sitalic,ipoints,ipixels);
  1589.         hdl = Nlm_XLoadQueryFont (Nlm_currentXDisplay, temp, FALSE);
  1590.         if (hdl) goto fontokay;
  1591.                 if (itlc) {
  1592.                      sitalic= "o";
  1593.                    sprintf(temp, "-*-%s-%s-%s-*--%d-%d-*",name,sbold,sitalic,ipoints,ipixels);
  1594.            hdl = Nlm_XLoadQueryFont (Nlm_currentXDisplay, temp, FALSE);
  1595.            if (hdl) goto fontokay;
  1596.                      }
  1597.                 if (bld) {
  1598.                      sbold= "demi";
  1599.                    sprintf(temp, "-*-%s-%s-%s-*--%d-%d-*",name,sbold,sitalic,ipoints,ipixels);
  1600.            hdl = Nlm_XLoadQueryFont (Nlm_currentXDisplay, temp, FALSE);
  1601.            if (hdl) goto fontokay;
  1602.                      }
  1603.  
  1604.                 /* try it based on family... */
  1605.                 if (fmly != NULL && fmly [0] != '\0') {
  1606.                     ipoints= 0;    /* to select scalable font */
  1607.                     ipixels= size * 10; /* ?? */
  1608.                     if (itlc) sitalic= "i"; else sitalic= "r";   /* or "o" and "r" */
  1609.                     if (bld) sbold= "bold"; else sbold= "medium"; /* or "demi" and "light" */
  1610.               if (Nlm_StringICmp (fmly, "Roman") == 0
  1611.                   && Nlm_StringICmp(name, "times") != 0)  
  1612.                   name= "times"; 
  1613.               else if (Nlm_StringICmp (fmly, "Swiss") == 0
  1614.                   && Nlm_StringICmp(name, "helvetica") != 0)  
  1615.                   name= "helvetica"; 
  1616.               else if (Nlm_StringICmp (fmly, "Modern") == 0
  1617.                   && Nlm_StringICmp(name, "courier") != 0)  
  1618.                   name= "courier"; 
  1619.               else if (Nlm_StringICmp (fmly, "Script") == 0
  1620.                   && Nlm_StringICmp(name, "times") != 0)  
  1621.                   name= "times"; 
  1622.               else if (Nlm_StringICmp (fmly, "Decorative") == 0
  1623.                   && Nlm_StringICmp(name, "times") != 0)  
  1624.                   name= "times"; 
  1625.               else if (Nlm_StringICmp(name, "helvetica") != 0)  
  1626.                   name= "helvetica"; 
  1627.                   sprintf(temp, "-*-%s-%s-%s-*--%d-%d-*",name,sbold,sitalic,ipoints,ipixels);
  1628.             hdl = Nlm_XLoadQueryFont (Nlm_currentXDisplay, temp, FALSE);
  1629.             if (hdl) goto fontokay;
  1630.                 }
  1631.  
  1632.         /* try font sizes w/o other extra -- looks good */
  1633.         size2= 10 + size;
  1634.         size--; /* start 1 lower */
  1635.         do {
  1636.             sprintf(temp,"-*-%s-*--%d-*",name, (int)size);
  1637.           hdl = Nlm_XLoadQueryFont (Nlm_currentXDisplay, temp, FALSE);
  1638.           if (hdl) goto fontokay;
  1639.           size ++;
  1640.         } while (size < size2);
  1641.  
  1642. #endif
  1643.  
  1644.         StringCpy (temp, "-*-");
  1645.         StringCat (temp, name);
  1646.         StringCat (temp, "-*");
  1647.         hdl = Nlm_XLoadQueryFont (Nlm_currentXDisplay, temp, FALSE);
  1648.         if (hdl == NULL) {
  1649.           StringCpy (temp, "-*-helvetica-bold-r-*--14-*");
  1650.           hdl = Nlm_XLoadQueryFont (Nlm_currentXDisplay, temp, TRUE);
  1651.         }
  1652.       }
  1653.     }
  1654. #ifdef DCLAP
  1655. fontokay:
  1656. #endif
  1657.  
  1658. #endif
  1659.     Nlm_LoadFontData (rsult, NULL, name, size, scale, bld,
  1660.                       itlc, undrln, num, styl, hdl, NULL);
  1661.   }
  1662.   return rsult;
  1663. }
  1664.  
  1665. static Nlm_FonT Nlm_FindFont (Nlm_CharPtr name, Nlm_Int2 size,
  1666.                               Nlm_Boolean bld, Nlm_Boolean itlc,
  1667.                               Nlm_Boolean undrln)
  1668.  
  1669. {
  1670.   Nlm_FontData  fdata;
  1671.   Nlm_FonT      p;
  1672.   Nlm_FonT      rsult;
  1673.  
  1674.   rsult = NULL;
  1675.   if (name != NULL && name [0] != '\0') {
  1676.     p = Nlm_fontList;
  1677.     while (p != NULL && rsult == NULL) {
  1678.       Nlm_GetFontData (p, &fdata);
  1679.       if ((Nlm_StringICmp (fdata.name, name) == 0) &&
  1680.          fdata.size == size && fdata.bld == bld &&
  1681.          fdata.ital == itlc && fdata.undlin == undrln) {
  1682.         rsult = p;
  1683.       }
  1684.       p = fdata.next;
  1685.     }
  1686.   }
  1687.   return rsult;
  1688. }
  1689.  
  1690. extern Nlm_FonT Nlm_GetFont (Nlm_CharPtr name, Nlm_Int2 size,
  1691.                              Nlm_Boolean bld, Nlm_Boolean itlc,
  1692.                              Nlm_Boolean undrln, Nlm_CharPtr family)
  1693.  
  1694. {
  1695.   Nlm_FontData  fdata;
  1696.   Nlm_FonT      rsult;
  1697.  
  1698.   rsult = NULL;
  1699.   if (name != NULL && name [0] != '\0') {
  1700. #ifdef DCLAP
  1701. #ifdef WIN_MSWIN
  1702.         /* need to do here -- MSWIN chokes if we try to CreateNewFont lots of times */
  1703.             if (Nlm_StringICmp (name, "Courier") == 0) {
  1704.                 name= "Courier New";      /* newCourier= TRUE; */            
  1705.                 }
  1706. #endif
  1707. #ifdef notnow_WIN_X
  1708.     /* no underlined fonts in Motif/XWin !! */
  1709.     if (undrln) bld= true;
  1710. #endif
  1711. #endif
  1712.     rsult = Nlm_FindFont (name, size, bld, itlc, undrln);
  1713.     if (rsult == NULL) {
  1714.       rsult = Nlm_CreateNewFont (name, size, bld, itlc, undrln, family);
  1715.       Nlm_GetFontData (rsult, &fdata);
  1716.       fdata.next = Nlm_fontList;
  1717.       Nlm_SetFontData (rsult, &fdata);
  1718.       Nlm_fontList = rsult;
  1719.     }
  1720.   }
  1721.   return rsult;
  1722. }
  1723.  
  1724. static Nlm_FonT Nlm_ParseFontSpec (Nlm_CharPtr spec)
  1725.  
  1726. {
  1727.   Nlm_Boolean  bold;
  1728.   Nlm_CharPtr  fmly;
  1729.   Nlm_Boolean  ital;
  1730.   Nlm_Char     name [128];
  1731.   Nlm_CharPtr  p;
  1732.   Nlm_CharPtr  q;
  1733.   Nlm_CharPtr  r;
  1734.   Nlm_FonT     rsult;
  1735.   Nlm_Int2     size;
  1736.   Nlm_Char     temp [128];
  1737.   Nlm_Boolean  undr;
  1738.   int          val;
  1739.  
  1740.   rsult = NULL;
  1741.   if (spec != NULL && spec [0] != '\0') {
  1742.     fmly = NULL;
  1743.     bold = FALSE;
  1744.     ital = FALSE;
  1745.     undr = FALSE;
  1746.     Nlm_StringNCpy (name, spec, sizeof (name) - 1);
  1747.     p = Nlm_StringChr (name, ',');
  1748.     if (p != NULL) {
  1749.       *p = '\0';
  1750.       p++;
  1751.       q = Nlm_StringChr (p, ',');
  1752.       if (q != NULL) {
  1753.         *q = '\0';
  1754.         q++;
  1755.       }
  1756.       r = Nlm_StringChr (q, 'B');
  1757.       if (r == NULL) {
  1758.         r = Nlm_StringChr (q, 'b');
  1759.       }
  1760.       if (r != NULL) {
  1761.         bold = TRUE;
  1762.       }
  1763.       r = Nlm_StringChr (q, 'I');
  1764.       if (r == NULL) {
  1765.         r = Nlm_StringChr (q, 'i');
  1766.       }
  1767.       if (r != NULL) {
  1768.         ital = TRUE;
  1769.       }
  1770.       r = Nlm_StringChr (q, 'U');
  1771.       if (r == NULL) {
  1772.         r = Nlm_StringChr (q, 'u');
  1773.       }
  1774.       if (r != NULL) {
  1775.         undr = TRUE;
  1776.       }
  1777.       Nlm_StringNCpy (temp, p, sizeof (temp) - 1);
  1778.       if (sscanf (temp, "%d", &val) != EOF) {
  1779.         size = (Nlm_Int2) val;
  1780.         rsult = Nlm_GetFont (name, size, bold, ital, undr, fmly);
  1781.       }
  1782.     }
  1783.   }
  1784.   return rsult;
  1785. }
  1786.  
  1787. extern Nlm_FonT Nlm_ParseFont (Nlm_CharPtr spec)
  1788.  
  1789. {
  1790.   Nlm_Char     name [128];
  1791.   Nlm_CharPtr  p;
  1792.   Nlm_FonT     prtr;
  1793.   Nlm_CharPtr  q;
  1794.   Nlm_FonT     rsult;
  1795.  
  1796.   rsult = NULL;
  1797.   if (spec != NULL && spec [0] != '\0') {
  1798.     Nlm_StringNCpy (name, spec, sizeof (name) - 1);
  1799.     p = Nlm_StringChr (name, '|');
  1800.     if (p != NULL) {
  1801.       *p = '\0';
  1802.       p++;
  1803.       while (*p == ' ') {
  1804.         p++;
  1805.       }
  1806.       q = name;
  1807.       while (*q == ' ') {
  1808.         q++;
  1809.       }
  1810.       rsult = Nlm_ParseFontSpec (q);
  1811.       prtr = Nlm_ParseFontSpec (p);
  1812.       Nlm_AssignPrinterFont (rsult, prtr);
  1813.     } else {
  1814.       q = name;
  1815.       while (*q == ' ') {
  1816.         q++;
  1817.       }
  1818.       rsult = Nlm_ParseFontSpec (q);
  1819.     }
  1820.   }
  1821.   return rsult;
  1822. }
  1823.  
  1824. extern void Nlm_SelectFont (Nlm_FonT f)
  1825.  
  1826. {
  1827.   Nlm_FontData  fdata;
  1828.  
  1829.   if (f != NULL) {
  1830.     Nlm_GetFontData (f, &fdata);
  1831.     if (fdata.print != NULL && Nlm_nowPrinting) {
  1832.       f = fdata.print;
  1833.       Nlm_GetFontData (f, &fdata);
  1834.     }
  1835. #ifdef WIN_MAC
  1836.     TextFont (fdata.number);
  1837.     TextSize (fdata.size);
  1838.     TextFace (fdata.style);
  1839. #endif
  1840. #ifdef WIN_MSWIN
  1841.     if (Nlm_currentHDC != NULL) {
  1842.       SelectObject (Nlm_currentHDC, fdata.handle);
  1843.     }
  1844. #endif
  1845. #ifdef WIN_X
  1846.     if (Nlm_currentXDisplay != NULL && Nlm_currentXGC != NULL) {
  1847.       if (fdata.handle != NULL) {
  1848.         XSetFont (Nlm_currentXDisplay, Nlm_currentXGC, fdata.handle->fid);
  1849.         currentFont = fdata.handle;
  1850.       }
  1851.     }
  1852. #endif
  1853.     Nlm_fontInUse = f;
  1854.   }
  1855. }
  1856.  
  1857.  
  1858. #if defined(DCLAP) && defined(WIN_X)
  1859. void Nlm_DoUline( Nlm_PoinT pt1, Nlm_Int4 x2, Nlm_Int2 ascent)
  1860. {
  1861.   Nlm_FontData  fdata;
  1862.     Nlm_GetFontData (Nlm_fontInUse, &fdata);
  1863.     if ( fdata.undlin ) {
  1864.     XDrawLine (Nlm_currentXDisplay, Nlm_currentXWindow, Nlm_currentXGC,
  1865.                pt1.x - Nlm_XOffset, pt1.y + ascent - Nlm_YOffset,
  1866.                x2 - Nlm_XOffset, pt1.y  + ascent - Nlm_YOffset);
  1867.         }
  1868. }
  1869. #endif
  1870.  
  1871. extern void Nlm_AssignPrinterFont (Nlm_FonT scrnFont, Nlm_FonT prtrFont)
  1872.  
  1873. {
  1874.   Nlm_FontData  fdata;
  1875.  
  1876.   if (scrnFont != NULL) {
  1877.     Nlm_GetFontData (scrnFont, &fdata);
  1878.     fdata.print = prtrFont;
  1879.     Nlm_SetFontData (scrnFont, &fdata);
  1880.   }
  1881. }
  1882.  
  1883. extern Nlm_Int2 Nlm_CharWidth (Nlm_Char ch)
  1884.  
  1885. {
  1886. #ifdef WIN_MAC
  1887.   return (CharWidth (ch));
  1888. #endif
  1889. #ifdef WIN_MSWIN
  1890.   Nlm_Char  str [4];
  1891.  
  1892.   str [0] = ch;
  1893.   str [1] = '\0';
  1894.   return (Nlm_TextWidth (str, 1));
  1895. #endif
  1896. #ifdef WIN_X
  1897.   Nlm_Char  str [4];
  1898.  
  1899.   str [0] = ch;
  1900.   str [1] = '\0';
  1901.   return (Nlm_TextWidth (str, 1));
  1902. #endif
  1903. }
  1904.  
  1905. extern Nlm_Int2 Nlm_StringWidth (Nlm_CharPtr text)
  1906.  
  1907. {
  1908.   return Nlm_TextWidth (text, Nlm_StringLen (text));
  1909. }
  1910.  
  1911. extern Nlm_Int2 Nlm_TextWidth (Nlm_CharPtr text, Nlm_sizeT len)
  1912.  
  1913. {
  1914. #ifdef WIN_MAC
  1915.   Nlm_Int2  rsult;
  1916.  
  1917.   rsult = 0;
  1918.   if (text != NULL && len > 0) {
  1919.     rsult = TextWidth (text, 0, (Nlm_Int2) len);
  1920.   }
  1921.   return rsult;
  1922. #endif
  1923. #ifdef WIN_MSWIN
  1924.   Nlm_Int2  rsult;
  1925.   HDC       hDC;
  1926.   SIZE      tag;
  1927.  
  1928.   rsult = 0;
  1929.   if (text != NULL && len > 0) {
  1930.     if (Nlm_currentHDC != NULL) {
  1931.       GetTextExtentPoint (Nlm_currentHDC, text, (Nlm_Int2) len, &tag);
  1932.     } else {
  1933.       hDC = CreateIC ("DISPLAY", NULL, NULL, NULL);
  1934.       GetTextExtentPoint (hDC, text, (Nlm_Int2) len, &tag);
  1935.       DeleteDC (hDC);
  1936.     }
  1937.     rsult = (Nlm_Int2) tag.cx;
  1938.   }
  1939.   return rsult;
  1940. #endif
  1941. #ifdef WIN_X
  1942.   Nlm_Int2  rsult;
  1943.  
  1944.   rsult = 0;
  1945.   if (text != NULL && len > 0 && Nlm_GetTextMetrics ()) {
  1946.     rsult = XTextWidth (&fontInfo, text, (int) len);
  1947.   }
  1948.   return rsult;
  1949. #endif
  1950. }
  1951.  
  1952. extern Nlm_Int2 Nlm_Ascent (void)
  1953.  
  1954. {
  1955. #ifdef WIN_MAC
  1956.   FontInfo  fontinfo;
  1957.  
  1958.   GetFontInfo (&fontinfo);
  1959.   return (fontinfo.ascent);
  1960. #endif
  1961. #ifdef WIN_MSWIN
  1962.   Nlm_Int2  rsult;
  1963.  
  1964.   rsult = 0;
  1965.   if (Nlm_GetTextMetrics ()) {
  1966.     rsult = (Nlm_Int2) textMetrics.tmAscent;
  1967.   }
  1968.   return rsult;
  1969. #endif
  1970. #ifdef WIN_X
  1971.   Nlm_Int2  rsult;
  1972.  
  1973.   rsult = 0;
  1974.   if (Nlm_GetTextMetrics ()) {
  1975.     rsult = fontInfo.ascent;
  1976.   }
  1977.   return rsult;
  1978. #endif
  1979. }
  1980.  
  1981. extern Nlm_Int2 Nlm_Descent (void)
  1982.  
  1983. {
  1984. #ifdef WIN_MAC
  1985.   FontInfo  fontinfo;
  1986.  
  1987.   GetFontInfo (&fontinfo);
  1988.   return (fontinfo.descent);
  1989. #endif
  1990. #ifdef WIN_MSWIN
  1991.   Nlm_Int2  rsult;
  1992.  
  1993.   rsult = 0;
  1994.   if (Nlm_GetTextMetrics ()) {
  1995.     rsult = (Nlm_Int2) textMetrics.tmDescent;
  1996.   }
  1997.   return rsult;
  1998. #endif
  1999. #ifdef WIN_X
  2000.   Nlm_Int2  rsult;
  2001.  
  2002.   rsult = 0;
  2003.   if (Nlm_GetTextMetrics ()) {
  2004.     rsult = fontInfo.descent;
  2005.   }
  2006.   return rsult;
  2007. #endif
  2008. }
  2009.  
  2010. extern Nlm_Int2 Nlm_Leading (void)
  2011.  
  2012. {
  2013. #ifdef WIN_MAC
  2014.   FontInfo  fontinfo;
  2015.  
  2016.   GetFontInfo (&fontinfo);
  2017.   return (fontinfo.leading);
  2018. #endif
  2019. #ifdef WIN_MSWIN
  2020.   Nlm_Int2  rsult;
  2021.  
  2022.   rsult = 0;
  2023.   if (Nlm_GetTextMetrics ()) {
  2024.     rsult = (Nlm_Int2) textMetrics.tmExternalLeading;
  2025.   }
  2026.   return rsult;
  2027. #endif
  2028. #ifdef WIN_X
  2029.   return 0;
  2030. #endif
  2031. }
  2032.  
  2033. extern Nlm_Int2 Nlm_FontHeight (void)
  2034.  
  2035. {
  2036. #ifdef WIN_MAC
  2037.   FontInfo  fontinfo;
  2038.  
  2039.   GetFontInfo (&fontinfo);
  2040.   return (fontinfo.ascent + fontinfo.descent);
  2041. #endif
  2042. #ifdef WIN_MSWIN
  2043.   Nlm_Int2  rsult;
  2044.  
  2045.   rsult = 0;
  2046.   if (Nlm_GetTextMetrics ()) {
  2047.     rsult = (Nlm_Int2) textMetrics.tmHeight;
  2048.   }
  2049.   return rsult;
  2050. #endif
  2051. #ifdef WIN_X
  2052.   Nlm_Int2  rsult;
  2053.  
  2054.   rsult = 0;
  2055.   if (Nlm_GetTextMetrics ()) {
  2056.     rsult = (fontInfo.ascent + fontInfo.descent);
  2057.   }
  2058.   return rsult;
  2059. #endif
  2060. }
  2061.  
  2062. extern Nlm_Int2 Nlm_LineHeight (void)
  2063.  
  2064. {
  2065. #ifdef WIN_MAC
  2066.   FontInfo  fontinfo;
  2067.  
  2068.   GetFontInfo (&fontinfo);
  2069.   return (fontinfo.ascent + fontinfo.descent + fontinfo.leading);
  2070. #endif
  2071. #ifdef WIN_MSWIN
  2072.   Nlm_Int2  rsult;
  2073.  
  2074.   rsult = 0;
  2075.   if (Nlm_GetTextMetrics ()) {
  2076.     rsult = (Nlm_Int2) (textMetrics.tmHeight + textMetrics.tmExternalLeading);
  2077.   }
  2078.   return rsult;
  2079. #endif
  2080. #ifdef WIN_X
  2081.   Nlm_Int2  rsult;
  2082.  
  2083.   rsult = 0;
  2084.   if (Nlm_GetTextMetrics ()) {
  2085.     rsult = (fontInfo.ascent + fontInfo.descent);
  2086.   }
  2087.   return rsult;
  2088. #endif
  2089. }
  2090.  
  2091. extern Nlm_Int2 Nlm_MaxCharWidth (void)
  2092.  
  2093. {
  2094. #ifdef WIN_MAC
  2095.   FontInfo  fontinfo;
  2096.  
  2097.   GetFontInfo (&fontinfo);
  2098.   return (fontinfo.widMax);
  2099. #endif
  2100. #ifdef WIN_MSWIN
  2101.   Nlm_Int2  rsult;
  2102.  
  2103.   rsult = 0;
  2104.   if (Nlm_GetTextMetrics ()) {
  2105.     rsult = (Nlm_Int2) textMetrics.tmMaxCharWidth;
  2106.   }
  2107.   return rsult;
  2108. #endif
  2109. #ifdef WIN_X
  2110.   Nlm_Int2  rsult;
  2111.  
  2112.   rsult = 0;
  2113.   if (Nlm_GetTextMetrics ()) {
  2114.     rsult = fontInfo.max_bounds.width;
  2115.   }
  2116.   return rsult;
  2117. #endif
  2118. }
  2119.  
  2120. extern void Nlm_SetPen (Nlm_PoinT pt)
  2121.  
  2122. {
  2123. #ifdef WIN_MAC
  2124.   MoveTo (pt.x, pt.y);
  2125. #endif
  2126. #ifdef WIN_MSWIN
  2127.   if (Nlm_currentHDC != NULL) {
  2128.     MoveToEx (Nlm_currentHDC, pt.x, pt.y, NULL);
  2129.   }
  2130. #endif
  2131. #ifdef WIN_X
  2132.   currentPoint = pt;
  2133. #endif
  2134. }
  2135.  
  2136. extern void Nlm_GetPen (Nlm_PointPtr pt)
  2137.  
  2138. {
  2139. #ifdef WIN_MAC
  2140.   Nlm_PointTool  ptool;
  2141.  
  2142.   if (pt != NULL) {
  2143.     GetPen (&ptool);
  2144.     Nlm_PointToolToPoinT (ptool, pt);
  2145.   }
  2146. #endif
  2147. #ifdef WIN_MSWIN
  2148.   POINT  pos;
  2149.  
  2150.   if (pt != NULL && Nlm_currentHDC != NULL) {
  2151.     GetCurrentPositionEx (Nlm_currentHDC, &pos);
  2152.     pt->x = (Nlm_Int2) pos.x;
  2153.     pt->y = (Nlm_Int2) pos.y;
  2154.   }
  2155. #endif
  2156. #ifdef WIN_X
  2157.   if (pt != NULL) {
  2158.     *pt = currentPoint;
  2159.   }
  2160. #endif
  2161. }
  2162.  
  2163. #ifdef DCLAP
  2164. extern void Nlm_TextOpaque()
  2165. {
  2166. #ifdef WIN_MAC
  2167.   /* TextMode (srcCopy); */
  2168. #endif
  2169. #ifdef WIN_MSWIN
  2170.   if (Nlm_currentHDC != NULL) SetBkMode (Nlm_currentHDC, OPAQUE);
  2171. #endif
  2172. #ifdef WIN_X
  2173. #endif
  2174. }
  2175.  
  2176. extern void Nlm_TextTransparent()
  2177. {
  2178. #ifdef WIN_MAC
  2179.   /* TextMode (srcOr); */
  2180. #endif
  2181. #ifdef WIN_MSWIN
  2182.   if (Nlm_currentHDC != NULL) SetBkMode (Nlm_currentHDC, TRANSPARENT);
  2183. #endif
  2184. #ifdef WIN_X
  2185. #endif
  2186. }
  2187.  
  2188. #endif
  2189.  
  2190.  
  2191. extern void Nlm_PaintChar (Nlm_Char ch)
  2192.  
  2193. {
  2194. #ifdef WIN_MAC
  2195.   DrawChar (ch);
  2196. #endif
  2197. #ifdef WIN_MSWIN
  2198.   Nlm_PoinT  pt;
  2199.   Nlm_Char   str [2];
  2200.  
  2201.   if (Nlm_currentHDC != NULL) {
  2202.     str [0] = ch;
  2203.     str [1] = '\0';
  2204.     Nlm_GetPen (&pt);
  2205.     TextOut (Nlm_currentHDC, pt.x, pt.y - Nlm_Ascent (), str, 1);
  2206.     pt.x += Nlm_CharWidth (ch);
  2207.     Nlm_MoveTo (pt.x, pt.y);
  2208.   }
  2209. #endif
  2210. #ifdef WIN_X
  2211.   Nlm_PoinT  pt;
  2212.   Nlm_Char   str [2];
  2213.  
  2214.   if (Nlm_currentXDisplay != NULL && Nlm_currentXWindow != 0 &&
  2215.       Nlm_currentXGC != NULL) {
  2216.     str [0] = ch;
  2217.     str [1] = '\0';
  2218.     Nlm_GetPen (&pt);
  2219.     XDrawString (Nlm_currentXDisplay, Nlm_currentXWindow, Nlm_currentXGC,
  2220.                  pt.x - Nlm_XOffset, pt.y - Nlm_YOffset, str, 1);
  2221. #ifdef DCLAP
  2222.     /* do uline... */
  2223.     {
  2224.         Nlm_Int4 ptx1 = pt.x + Nlm_CharWidth (ch);
  2225.         Nlm_DoUline( pt, ptx1, 0);
  2226.     pt.x = ptx1;
  2227.         }
  2228. #else
  2229.     pt.x += Nlm_CharWidth (ch);
  2230. #endif
  2231.     Nlm_MoveTo (pt.x, pt.y);
  2232.   }
  2233. #endif
  2234. }
  2235.  
  2236. extern void Nlm_PaintString (Nlm_CharPtr text)
  2237.  
  2238. {
  2239. #ifdef WIN_MAC
  2240.   Nlm_PoinT  pt;
  2241.   Nlm_Char   str [256];
  2242.  
  2243.   if (text != NULL) {
  2244.     Nlm_GetPen (&pt);
  2245. #ifdef DCLAP
  2246.        if (*text) drawstring ( text);
  2247. #else
  2248.     if (Nlm_StringLen (text) > 0) {
  2249.       Nlm_StringNCpy (str, text, sizeof (str));
  2250.       Nlm_CtoPstr (str);
  2251.       DrawString ((StringPtr) str);
  2252.     }
  2253. #endif
  2254.     pt.x += Nlm_StringWidth (text);
  2255.     Nlm_MoveTo (pt.x, pt.y);
  2256.   }
  2257. #endif
  2258. #ifdef WIN_MSWIN
  2259.   Nlm_Int2   len;
  2260.   Nlm_PoinT  pt;
  2261.  
  2262.   if (text != NULL && Nlm_currentHDC != NULL) {
  2263.     len = (Nlm_Int2) Nlm_StringLen (text);
  2264.     Nlm_GetPen (&pt);
  2265.     if (len > 0) {
  2266.       TextOut (Nlm_currentHDC, pt.x, pt.y - Nlm_Ascent (), text, len);
  2267.     }
  2268.     pt.x += Nlm_StringWidth (text);
  2269.     Nlm_MoveTo (pt.x, pt.y);
  2270.   }
  2271. #endif
  2272. #ifdef WIN_X
  2273.   Nlm_Int2   len;
  2274.   Nlm_PoinT  pt;
  2275.  
  2276.   if (text != NULL && Nlm_currentXDisplay != NULL &&
  2277.       Nlm_currentXWindow != 0 && Nlm_currentXGC != NULL) {
  2278.     len = (Nlm_Int2) Nlm_StringLen (text);
  2279.     Nlm_GetPen (&pt);
  2280.     if (len > 0) {
  2281.       XDrawString (Nlm_currentXDisplay, Nlm_currentXWindow, Nlm_currentXGC,
  2282.                    pt.x - Nlm_XOffset, pt.y - Nlm_YOffset, text, len);
  2283.     }
  2284. #ifdef DCLAP
  2285.     /* do uline... */
  2286.     {
  2287.         Nlm_Int4 ptx1 = pt.x + Nlm_StringWidth (text);
  2288.         Nlm_DoUline( pt, ptx1, 0);
  2289.     pt.x = ptx1;
  2290.         }
  2291. #else
  2292.     pt.x += Nlm_StringWidth (text);
  2293. #endif
  2294.     Nlm_MoveTo (pt.x, pt.y);
  2295.   }
  2296. #endif
  2297. }
  2298.  
  2299. #ifdef VAR_ARGS
  2300. void CDECL Nlm_PaintText (format, va_alist)
  2301.   char *format;
  2302.   va_dcl
  2303. #else
  2304. void CDECL Nlm_PaintText (char *format, ...)
  2305. #endif
  2306.  
  2307. {
  2308. #ifdef WIN_MAC
  2309.   va_list    args;
  2310.   Nlm_PoinT  pt;
  2311.   Nlm_Char   str [256];
  2312.  
  2313.   if (format != NULL) {
  2314. #ifdef VAR_ARGS
  2315.     va_start(args);
  2316. #else
  2317.     va_start(args, format);
  2318. #endif
  2319.     vsprintf(str, format, args);
  2320.     va_end(args);
  2321.     Nlm_GetPen (&pt);
  2322.     if (Nlm_StringLen (str) > 0) {
  2323.       Nlm_CtoPstr (str);
  2324.       DrawString ((StringPtr) str);
  2325.     }
  2326.     pt.y += Nlm_LineHeight ();
  2327.     Nlm_MoveTo (pt.x, pt.y);
  2328.   }
  2329. #endif
  2330. #ifdef WIN_MSWIN
  2331.   va_list    args;
  2332.   Nlm_Int2   len;
  2333.   Nlm_PoinT  pt;
  2334.   Nlm_Char   str [256];
  2335.  
  2336.   if (format != NULL && Nlm_currentHDC != NULL) {
  2337. #ifdef VAR_ARGS
  2338.     va_start(args);
  2339. #else
  2340.     va_start(args, format);
  2341. #endif
  2342.     vsprintf(str, format, args);
  2343.     va_end(args);
  2344.     len = (Nlm_Int2) Nlm_StringLen (str);
  2345.     Nlm_GetPen (&pt);
  2346.     if (len > 0) {
  2347.       TextOut (Nlm_currentHDC, pt.x, pt.y - Nlm_Ascent (), str, len);
  2348.     }
  2349.     pt.y += Nlm_LineHeight ();
  2350.     Nlm_MoveTo (pt.x, pt.y);
  2351.   }
  2352. #endif
  2353. #ifdef WIN_X
  2354.   va_list    args;
  2355.   Nlm_Int2   len;
  2356.   Nlm_PoinT  pt;
  2357.   Nlm_Char   str [256];
  2358.  
  2359.   if (format != NULL && Nlm_currentXDisplay != NULL &&
  2360.       Nlm_currentXWindow != 0 && Nlm_currentXGC != NULL) {
  2361. #ifdef VAR_ARGS
  2362.     va_start(args);
  2363. #else
  2364.     va_start(args, format);
  2365. #endif
  2366.     vsprintf(str, format, args);
  2367.     va_end(args);
  2368.     len = (Nlm_Int2) Nlm_StringLen (str);
  2369.     Nlm_GetPen (&pt);
  2370.     if (len > 0) {
  2371.       XDrawString (Nlm_currentXDisplay, Nlm_currentXWindow, Nlm_currentXGC,
  2372.                    pt.x - Nlm_XOffset, pt.y - Nlm_YOffset, str, len);
  2373.     }
  2374.     pt.y += Nlm_LineHeight ();
  2375.     Nlm_MoveTo (pt.x, pt.y);
  2376.   }
  2377. #endif
  2378. }
  2379.  
  2380. extern void Nlm_DrawString (Nlm_RectPtr r, Nlm_CharPtr text,
  2381.                             Nlm_Char jst, Nlm_Boolean gray)
  2382.  
  2383. {
  2384.   Nlm_DrawText (r, text, Nlm_StringLen (text), jst, gray);
  2385. }
  2386.  
  2387. extern void Nlm_DrawText (Nlm_RectPtr r, Nlm_CharPtr text,
  2388.                           Nlm_sizeT len, Nlm_Char jst,
  2389.                           Nlm_Boolean gray)
  2390.  
  2391. {
  2392. #ifdef WIN_MAC
  2393.   Nlm_Int2      delta;
  2394.   Nlm_Int2      height;
  2395.   Nlm_Int2      just;
  2396.   Nlm_Int2      limit;
  2397.   PenState      pnState;
  2398.   Nlm_RectTool  rtool;
  2399.  
  2400.   if (r != NULL) {
  2401.     Nlm_EraseRect (r);
  2402.     if (text != NULL && len > 0) {
  2403.       Nlm_RecTToRectTool (r, &rtool);
  2404.       limit = ABS (r->bottom - r->top);
  2405.       height = Nlm_LineHeight ();
  2406.       delta = limit - height;
  2407.       if (delta > 0) {
  2408.         rtool.top += delta / 2;
  2409.         rtool.bottom = rtool.top + height;
  2410.       }
  2411.       switch (jst) {
  2412.         case 'r':
  2413.           just = -1;
  2414.           break;
  2415.         case 'l':
  2416.           just = 0;
  2417.           break;
  2418.         case 'c':
  2419.           just = 1;
  2420.           break;
  2421.         default:
  2422.           just = 0;
  2423.           break;
  2424.       }
  2425.       TextBox (text, len, &rtool, just);
  2426.       if (gray) {
  2427.         GetPenState (&pnState);
  2428.         PenMode (patBic);
  2429.         PenPat ((ConstPatternParam) grayPat);
  2430.         PaintRect (&rtool);
  2431.         SetPenState (&pnState);
  2432.       }
  2433.     }
  2434.   }
  2435. #endif
  2436. #ifdef WIN_MSWIN
  2437.   Nlm_Int2      format;
  2438.   Nlm_Int4      oldcolor;
  2439.   Nlm_RectTool  rtool;
  2440.  
  2441.   if (r != NULL && Nlm_currentHDC != NULL) {
  2442.     Nlm_RecTToRectTool (r, &rtool);
  2443.     if (Nlm_currentHWnd != NULL) {
  2444.       Nlm_EraseRect (r);
  2445.     } else {
  2446.       FillRect (Nlm_currentHDC, &rtool, hWhiteBrush);
  2447.     }
  2448.     if (text != NULL && len > 0) {
  2449.       switch (jst) {
  2450.         case 'r':
  2451.           format = DT_RIGHT;
  2452.           break;
  2453.         case 'l':
  2454.           format = DT_LEFT;
  2455.           break;
  2456.         case 'c':
  2457.           format = DT_CENTER;
  2458.           break;
  2459.         default:
  2460.           format = DT_LEFT;
  2461.           break;
  2462.       }
  2463.       if (gray) {
  2464.         oldcolor = SetTextColor (Nlm_currentHDC, GetSysColor (COLOR_GRAYTEXT));
  2465.       }
  2466.       DrawText (Nlm_currentHDC, text, (Nlm_Int2) len, &rtool,
  2467.                 format | DT_VCENTER | DT_NOPREFIX);
  2468.       if (gray) {
  2469.         SetTextColor (Nlm_currentHDC, oldcolor);
  2470.       }
  2471.     }
  2472.   }
  2473. #endif
  2474. #ifdef WIN_X
  2475.   Nlm_Int2   delta;
  2476.   Nlm_Int2   height;
  2477.   Nlm_Int2   limit;
  2478.   Pixmap     pix;
  2479.   Nlm_PoinT  pt;
  2480.   Nlm_IntD   width;
  2481.  
  2482.   if (r != NULL && Nlm_currentXDisplay != NULL &&
  2483.       Nlm_currentXWindow != 0 && Nlm_currentXGC != NULL) {
  2484.     Nlm_EraseRect (r);
  2485.     if (text != NULL && len > 0) {
  2486.       pt.x = r->left;
  2487.       pt.y = r->top;
  2488.       limit = ABS (r->right - r->left);
  2489.       width = Nlm_TextWidth (text, len);
  2490.       while (len > 0 && width > limit) {
  2491.         len--;
  2492.         width = Nlm_TextWidth (text, len);
  2493.       }
  2494.       delta = limit - width;
  2495.       switch (jst) {
  2496.         case 'r':
  2497.           pt.x += delta;
  2498.           break;
  2499.         case 'l':
  2500.           break;
  2501.         case 'c':
  2502.           pt.x += delta / 2;
  2503.           break;
  2504.         default:
  2505.           break;
  2506.       }
  2507.       limit = ABS (r->bottom - r->top);
  2508.       height = Nlm_LineHeight ();
  2509.       delta = limit - height;
  2510.       if (delta > 0) {
  2511.         pt.y += delta / 2;
  2512.       }
  2513.       if (limit >= height) {
  2514.         if (gray) {
  2515.           pix = XCreateBitmapFromData (Nlm_currentXDisplay, Nlm_currentXWindow,
  2516.                                        (char *) grayPat, 8, 8);
  2517.           if (pix != 0 && Nlm_currentXGC != NULL) {
  2518.             XSetStipple (Nlm_currentXDisplay, Nlm_currentXGC, pix);
  2519.           }
  2520.         }
  2521.         XDrawString (Nlm_currentXDisplay, Nlm_currentXWindow, Nlm_currentXGC,
  2522.                      pt.x - Nlm_XOffset, pt.y + Nlm_Ascent () - Nlm_YOffset,
  2523.                      text, (int) len);
  2524. #ifdef DCLAP
  2525.                 /* do uline... */
  2526.             {
  2527.                 Nlm_Int4 ptx1 = pt.x + Nlm_StringWidth (text);
  2528.                 Nlm_DoUline( pt, ptx1, Nlm_Ascent());
  2529.                 }
  2530. #endif
  2531.         if (gray && pix != 0) {
  2532.           XFreePixmap (Nlm_currentXDisplay, pix);
  2533.           if (Nlm_currentXGC != NULL) {
  2534.             XSetStipple (Nlm_currentXDisplay, Nlm_currentXGC, currentPixmap);
  2535.           }
  2536.         }
  2537.       }
  2538.     }
  2539.   }
  2540. #endif
  2541. }
  2542.  
  2543. extern void Nlm_MoveTo (Nlm_IntD x, Nlm_IntD y)
  2544.  
  2545. {
  2546. #ifdef WIN_MAC
  2547.   MoveTo (x, y);
  2548. #endif
  2549. #ifdef WIN_MSWIN
  2550.   if (Nlm_currentHDC != NULL) {
  2551.     MoveToEx (Nlm_currentHDC, x, y, NULL);
  2552.   }
  2553. #endif
  2554. #ifdef WIN_X
  2555.   currentPoint.x = x;
  2556.   currentPoint.y = y;
  2557. #endif
  2558. }
  2559.  
  2560. extern void Nlm_LineTo (Nlm_IntD x, Nlm_IntD y)
  2561.  
  2562. {
  2563. #ifdef WIN_MAC
  2564.   LineTo (x, y);
  2565. #endif
  2566. #ifdef WIN_MSWIN
  2567.   if (Nlm_currentHDC != NULL) {
  2568.     SetBkMode (Nlm_currentHDC, TRANSPARENT);
  2569.     LineTo (Nlm_currentHDC, x, y);
  2570.     SetBkMode (Nlm_currentHDC, OPAQUE);
  2571.   }
  2572. #endif
  2573. #ifdef WIN_X
  2574.   if (Nlm_currentXDisplay != NULL && Nlm_currentXWindow != 0 &&
  2575.       Nlm_currentXGC != NULL) {
  2576.     XDrawLine (Nlm_currentXDisplay, Nlm_currentXWindow, Nlm_currentXGC,
  2577.                currentPoint.x - Nlm_XOffset, currentPoint.y - Nlm_YOffset,
  2578.                x - Nlm_XOffset, y - Nlm_YOffset);
  2579.     currentPoint.x = x;
  2580.     currentPoint.y = y;
  2581.   }
  2582. #endif
  2583. }
  2584.  
  2585. extern void Nlm_DrawLine (Nlm_PoinT pt1, Nlm_PoinT pt2)
  2586.  
  2587. {
  2588. #ifdef WIN_MAC
  2589.   MoveTo (pt1.x, pt1.y);
  2590.   LineTo (pt2.x, pt2.y);
  2591. #endif
  2592. #ifdef WIN_MSWIN
  2593.   if (Nlm_currentHDC != NULL) {
  2594.     MoveToEx (Nlm_currentHDC, pt1.x, pt1.y, NULL);
  2595.     SetBkMode (Nlm_currentHDC, TRANSPARENT);
  2596.     LineTo (Nlm_currentHDC, pt2.x, pt2.y);
  2597.     SetBkMode (Nlm_currentHDC, OPAQUE);
  2598.   }
  2599. #endif
  2600. #ifdef WIN_X
  2601.   if (Nlm_currentXDisplay != NULL && Nlm_currentXWindow != 0 &&
  2602.       Nlm_currentXGC != NULL) {
  2603.     XDrawLine (Nlm_currentXDisplay, Nlm_currentXWindow, Nlm_currentXGC,
  2604.                pt1.x - Nlm_XOffset, pt1.y - Nlm_YOffset,
  2605.                pt2.x - Nlm_XOffset, pt2.y - Nlm_YOffset);
  2606.     currentPoint.x = pt2.x;
  2607.     currentPoint.y = pt2.y;
  2608.   }
  2609. #endif
  2610. }
  2611.  
  2612. extern void Nlm_LoadPt (Nlm_PointPtr pt, Nlm_IntD x, Nlm_IntD y)
  2613.  
  2614. {
  2615.   if (pt != NULL) {
  2616.     pt->x = x;
  2617.     pt->y = y;
  2618.   }
  2619. }
  2620.  
  2621. extern void Nlm_AddPt (Nlm_PoinT src, Nlm_PointPtr dst)
  2622.  
  2623. {
  2624.   if (dst != NULL) {
  2625.     dst->x += src.x;
  2626.     dst->y += src.y;
  2627.   }
  2628. }
  2629.  
  2630. extern void Nlm_SubPt (Nlm_PoinT src, Nlm_PointPtr dst)
  2631.  
  2632. {
  2633.   if (dst != NULL) {
  2634.     dst->x -= src.x;
  2635.     dst->y -= src.y;
  2636.   }
  2637. }
  2638.  
  2639. extern Nlm_Boolean Nlm_EqualPt (Nlm_PoinT p1, Nlm_PoinT p2)
  2640.  
  2641. {
  2642.   return (Nlm_Boolean) (p1.x == p2.x && p1.y == p2.y);
  2643. }
  2644.  
  2645. extern Nlm_Boolean Nlm_PtInRect (Nlm_PoinT pt, Nlm_RectPtr r)
  2646.  
  2647. {
  2648.   return (Nlm_Boolean) (r != NULL && pt.x >= r->left && pt.x < r->right &&
  2649.                         pt.y >= r->top && pt.y < r->bottom);
  2650. }
  2651.  
  2652. extern Nlm_Boolean Nlm_PtInRgn (Nlm_PoinT pt, Nlm_RegioN rgn)
  2653.  
  2654. {
  2655.   Nlm_RgnTool    ntool;
  2656.   Nlm_Boolean    rsult;
  2657. #ifdef WIN_MAC
  2658.   Nlm_PointTool  ptool;
  2659. #endif
  2660.  
  2661.   rsult = FALSE;
  2662.   if (rgn != NULL) {
  2663.     ntool = (Nlm_RgnTool) rgn;
  2664. #ifdef WIN_MAC
  2665.     Nlm_PoinTToPointTool (pt, &ptool);
  2666.     rsult = PtInRgn (ptool, ntool);
  2667. #endif
  2668. #ifdef WIN_MSWIN
  2669.     rsult = (Nlm_Boolean) PtInRegion (ntool, pt.x, pt.y);
  2670. #endif
  2671. #ifdef WIN_X
  2672.     rsult = (XPointInRegion (ntool, pt.x, pt.y) != 0);
  2673. #endif
  2674.   }
  2675.   return rsult;
  2676. }
  2677.  
  2678. extern void Nlm_LoadRect (Nlm_RectPtr r, Nlm_IntD lf,
  2679.                           Nlm_IntD tp, Nlm_IntD rt,
  2680.                           Nlm_IntD bt)
  2681.  
  2682. {
  2683.   if (r != NULL) {
  2684.     r->left = lf;
  2685.     r->top = tp;
  2686.     r->right = rt;
  2687.     r->bottom = bt;
  2688.   }
  2689. }
  2690.  
  2691. extern void Nlm_UpsetRect (Nlm_RectPtr r, Nlm_IntD lf,
  2692.                            Nlm_IntD tp, Nlm_IntD rt,
  2693.                            Nlm_IntD bt)
  2694.  
  2695. {
  2696.   if (r != NULL) {
  2697.     r->left += lf;
  2698.     r->top += tp;
  2699.     r->right -= rt;
  2700.     r->bottom -= bt;
  2701.   }
  2702. }
  2703.  
  2704. extern void Nlm_OffsetRect (Nlm_RectPtr r, Nlm_IntD dx, Nlm_IntD dy)
  2705.  
  2706. {
  2707.   if (r != NULL) {
  2708.     r->left += dx;
  2709.     r->top += dy;
  2710.     r->right += dx;
  2711.     r->bottom += dy;
  2712.   }
  2713. }
  2714.  
  2715. extern void Nlm_InsetRect (Nlm_RectPtr r, Nlm_IntD dx, Nlm_IntD dy)
  2716.  
  2717. {
  2718.   if (r != NULL) {
  2719.     r->left += dx;
  2720.     r->top += dy;
  2721.     r->right -= dx;
  2722.     r->bottom -= dy;
  2723.   }
  2724. }
  2725.  
  2726. static void Nlm_LoadNormalized (Nlm_RectPtr dst, Nlm_RectPtr src)
  2727.  
  2728. {
  2729.   if (src != NULL && dst != NULL) {
  2730.     Nlm_LoadRect (dst, MIN (src->left, src->right), MIN (src->top, src->bottom),
  2731.                   MAX (src->left, src->right), MAX (src->top, src->bottom));
  2732.   }
  2733. }
  2734.  
  2735. extern Nlm_Boolean Nlm_SectRect (Nlm_RectPtr src1, Nlm_RectPtr src2,
  2736.                                  Nlm_RectPtr dst)
  2737.  
  2738. {
  2739.   Nlm_Boolean   rsult;
  2740.   Nlm_RectTool  rtool1;
  2741.   Nlm_RectTool  rtool2;
  2742.   Nlm_RectTool  rtool3;
  2743. #ifdef WIN_X
  2744.   Nlm_RecT      rct1;
  2745.   Nlm_RecT      rct2;
  2746. #endif
  2747.  
  2748.   rsult = FALSE;
  2749.   if (src1 != NULL && src2 != NULL && dst != NULL) {
  2750. #ifdef WIN_MAC
  2751.     Nlm_RecTToRectTool (src1, &rtool1);
  2752.     Nlm_RecTToRectTool (src2, &rtool2);
  2753.     rsult = SectRect (&rtool1, &rtool2, &rtool3);
  2754.     Nlm_RectToolToRecT (&rtool3, dst);
  2755. #endif
  2756. #ifdef WIN_MSWIN
  2757.     Nlm_RecTToRectTool (src1, &rtool1);
  2758.     Nlm_RecTToRectTool (src2, &rtool2);
  2759.     rsult = (Nlm_Boolean) IntersectRect (&rtool3, &rtool1, &rtool2);
  2760.     Nlm_RectToolToRecT (&rtool3, dst);
  2761. #endif
  2762. #ifdef WIN_X
  2763.     Nlm_LoadNormalized (&rct1, src1);
  2764.     Nlm_LoadNormalized (&rct2, src2);
  2765.     dst->left = MAX (rct1.left, rct2.left);
  2766.     dst->right = MIN (rct1.right, rct2.right);
  2767.     dst->top = MAX (rct1.top, rct2.top);
  2768.     dst->bottom = MIN (rct1.bottom, rct2.bottom);
  2769.     if (dst->left > dst->right || dst->top > dst->bottom) {
  2770.       Nlm_LoadRect (dst, 0, 0, 0, 0);
  2771.       }
  2772. #ifdef DCLAP
  2773.     /* ! NEED rsult ! */
  2774.     rsult= ( (rct1.left >= rct2.left && rct1.left <= rct2.right)
  2775.                 || (rct1.right >= rct2.left && rct1.right <= rct2.right) )
  2776.                 && 
  2777.               ( (rct1.top >= rct2.top && rct1.top <= rct2.bottom)
  2778.                 || (rct1.bottom >= rct2.top && rct1.bottom <= rct2.bottom) );
  2779. #endif
  2780. #endif
  2781.   }
  2782.   return rsult;
  2783. }
  2784.  
  2785. extern Nlm_Boolean Nlm_UnionRect (Nlm_RectPtr src1, Nlm_RectPtr src2,
  2786.                                   Nlm_RectPtr dst)
  2787.  
  2788. {
  2789.   Nlm_Boolean   rsult;
  2790.   Nlm_RectTool  rtool1;
  2791.   Nlm_RectTool  rtool2;
  2792.   Nlm_RectTool  rtool3;
  2793. #ifdef WIN_X
  2794.   Nlm_RecT      rct1;
  2795.   Nlm_RecT      rct2;
  2796. #endif
  2797.  
  2798.   rsult = FALSE;
  2799.   if (src1 != NULL && src2 != NULL && dst != NULL) {
  2800. #ifdef WIN_MAC
  2801.     Nlm_RecTToRectTool (src1, &rtool1);
  2802.     Nlm_RecTToRectTool (src2, &rtool2);
  2803.     UnionRect (&rtool1, &rtool2, &rtool3);
  2804.     rsult = EmptyRect (&rtool3);
  2805.     Nlm_RectToolToRecT (&rtool3, dst);
  2806. #endif
  2807. #ifdef WIN_MSWIN
  2808.     Nlm_RecTToRectTool (src1, &rtool1);
  2809.     Nlm_RecTToRectTool (src2, &rtool2);
  2810.     rsult = (Nlm_Boolean) UnionRect (&rtool3, &rtool1, &rtool2);
  2811.     Nlm_RectToolToRecT (&rtool3, dst);
  2812. #endif
  2813. #ifdef WIN_X
  2814.     Nlm_LoadNormalized (&rct1, src1);
  2815.     Nlm_LoadNormalized (&rct2, src2);
  2816.     dst->left = MIN (rct1.left, rct2.left);
  2817.     dst->right = MAX (rct1.right, rct2.right);
  2818.     dst->top = MIN (rct1.top, rct2.top);
  2819.     dst->bottom = MAX (rct1.bottom, rct2.bottom);
  2820. #endif
  2821.   }
  2822.   return rsult;
  2823. }
  2824.  
  2825. extern Nlm_Boolean Nlm_EqualRect (Nlm_RectPtr r1, Nlm_RectPtr r2)
  2826.  
  2827. {
  2828.   return (Nlm_Boolean) (r1 != NULL && r2 != NULL && r1->left == r2->left &&
  2829.                         r1->top == r2->top && r1->right == r2->right &&
  2830.                         r1->bottom == r2->bottom);
  2831. }
  2832.  
  2833. extern Nlm_Boolean Nlm_EmptyRect (Nlm_RectPtr r)
  2834.  
  2835. {
  2836.   return (Nlm_Boolean) ! (r != NULL && r->bottom > r->top && r->right > r->left);
  2837. }
  2838.  
  2839. extern Nlm_Boolean Nlm_RectInRect (Nlm_RectPtr r1, Nlm_RectPtr r2)
  2840.  
  2841. {
  2842.   Nlm_Boolean  rsult;
  2843.  
  2844.   rsult = FALSE;
  2845.   if (r1 != NULL && r2 != NULL &&
  2846.     r1->top >= r2->top && r1->bottom <= r2->bottom &&
  2847.     r1->left >= r2->left && r1->right <= r2->right) {
  2848.     rsult = TRUE;
  2849.   }
  2850.   return rsult;
  2851. }
  2852.  
  2853. extern Nlm_Boolean Nlm_RectInRgn (Nlm_RectPtr r, Nlm_RegioN rgn)
  2854.  
  2855. {
  2856.   Nlm_RgnTool   ntool;
  2857.   Nlm_Boolean   rsult;
  2858.   Nlm_RectTool  rtool;
  2859.  
  2860.   rsult = FALSE;
  2861.   if (r != NULL && rgn != NULL) {
  2862.     Nlm_RecTToRectTool (r, &rtool);
  2863.     ntool = (Nlm_RgnTool) rgn;
  2864. #ifdef WIN_MAC
  2865.     rsult = RectInRgn (&rtool, ntool);
  2866. #endif
  2867. #ifdef WIN_MSWIN
  2868.     rsult = (Nlm_Boolean) RectInRegion (ntool, &rtool);
  2869. #endif
  2870. #ifdef WIN_X
  2871.     rsult = (XRectInRegion (ntool, rtool.x, rtool.y, rtool.width, rtool.height) != 0);
  2872. #endif
  2873.   }
  2874.   return rsult;
  2875. }
  2876.  
  2877. extern void Nlm_EraseRect (Nlm_RectPtr r)
  2878.  
  2879. {
  2880. #ifdef WIN_MAC
  2881.   Nlm_RectTool  rtool;
  2882.  
  2883.   if (r != NULL) {
  2884.     Nlm_RecTToRectTool (r, &rtool);
  2885.     EraseRect (&rtool);
  2886.   }
  2887. #endif
  2888. #ifdef WIN_MSWIN
  2889.   Nlm_Int4      bkColor;
  2890.   HBRUSH        hBackBrush;
  2891.   Nlm_RectTool  rtool;
  2892.  
  2893.   if (r != NULL && Nlm_currentHDC != NULL && Nlm_currentHWnd != NULL) {
  2894.     Nlm_RecTToRectTool (r, &rtool);
  2895.     bkColor = GetBkColor (Nlm_currentHDC);
  2896.     hBackBrush = CreateSolidBrush (bkColor);
  2897.     FillRect (Nlm_currentHDC, &rtool, hBackBrush);
  2898.     DeleteObject (hBackBrush);
  2899.   }
  2900. #endif
  2901. #ifdef WIN_X
  2902.   Nlm_RectTool  rtool;
  2903.  
  2904.   if (r != NULL && Nlm_currentXDisplay != NULL && Nlm_currentXWindow != 0) {
  2905.     Nlm_RecTToRectTool (r, &rtool);
  2906.     XSetForeground (Nlm_currentXDisplay, Nlm_currentXGC, currentBkColor);
  2907.     XFillRectangle (Nlm_currentXDisplay, Nlm_currentXWindow, Nlm_currentXGC,
  2908.                     rtool.x - Nlm_XOffset, rtool.y - Nlm_YOffset,
  2909.                     rtool.width, rtool.height);
  2910.     XSetForeground (Nlm_currentXDisplay, Nlm_currentXGC, currentFgColor);
  2911.   }
  2912. #endif
  2913. }
  2914.  
  2915. extern void Nlm_FrameRect (Nlm_RectPtr r)
  2916.  
  2917. {
  2918. #ifdef WIN_MAC
  2919.   Nlm_RectTool  rtool;
  2920.  
  2921.   if (r != NULL) {
  2922.     Nlm_RecTToRectTool (r, &rtool);
  2923.     if (rtool.right == rtool.left) {
  2924.       rtool.right = rtool.left + 1;
  2925.     }
  2926.     if (rtool.bottom == rtool.top) {
  2927.       rtool.bottom = rtool.top + 1;
  2928.     }
  2929.     FrameRect (&rtool);
  2930.   }
  2931. #endif
  2932. #ifdef WIN_MSWIN
  2933.   HBRUSH        oldBrush;
  2934.   Nlm_RectTool  rtool;
  2935.  
  2936.   if (r != NULL && Nlm_currentHDC != NULL) {
  2937.     oldBrush = SelectObject (Nlm_currentHDC, GetStockObject (NULL_BRUSH));
  2938.     Nlm_RecTToRectTool (r, &rtool);
  2939.     if (rtool.right == rtool.left) {
  2940.       rtool.right = rtool.left + 1;
  2941.     }
  2942.     if (rtool.bottom == rtool.top) {
  2943.       rtool.bottom = rtool.top + 1;
  2944.     }
  2945.     Rectangle (Nlm_currentHDC, rtool.left, rtool.top, rtool.right, rtool.bottom);
  2946.     if (oldBrush != NULL) {
  2947.       SelectObject (Nlm_currentHDC, oldBrush);
  2948.     }
  2949.   }
  2950. #endif
  2951. #ifdef WIN_X
  2952.   Nlm_RectTool  rtool;
  2953.  
  2954.   if (r != NULL && Nlm_currentXDisplay != NULL &&
  2955.       Nlm_currentXWindow != 0 && Nlm_currentXGC != NULL) {
  2956.     Nlm_RecTToRectTool (r, &rtool);
  2957.     rtool.width = MAX (rtool.width, 1);
  2958.     rtool.height = MAX (rtool.height, 1);
  2959.     XDrawRectangle (Nlm_currentXDisplay, Nlm_currentXWindow, Nlm_currentXGC,
  2960.                     rtool.x - Nlm_XOffset, rtool.y - Nlm_YOffset,
  2961.                     rtool.width - 1, rtool.height - 1);
  2962.   }
  2963. #endif
  2964. }
  2965.  
  2966. extern void Nlm_PaintRect (Nlm_RectPtr r)
  2967.  
  2968. {
  2969. #ifdef WIN_MAC
  2970.   Nlm_RectTool  rtool;
  2971.  
  2972.   if (r != NULL) {
  2973.     Nlm_RecTToRectTool (r, &rtool);
  2974.     if (rtool.right == rtool.left) {
  2975.       rtool.right = rtool.left + 1;
  2976.     }
  2977.     if (rtool.bottom == rtool.top) {
  2978.       rtool.bottom = rtool.top + 1;
  2979.     }
  2980.     PaintRect (&rtool);
  2981.   }
  2982. #endif
  2983. #ifdef WIN_MSWIN
  2984.   HPEN          oldPen;
  2985.   Nlm_RectTool  rtool;
  2986.  
  2987.   if (r != NULL && Nlm_currentHDC != NULL) {
  2988.     oldPen = SelectObject (Nlm_currentHDC, GetStockObject (NULL_PEN));
  2989.     Nlm_RecTToRectTool (r, &rtool);
  2990.     if (rtool.right == rtool.left) {
  2991.       rtool.right = rtool.left + 1;
  2992.     }
  2993.     if (rtool.bottom == rtool.top) {
  2994.       rtool.bottom = rtool.top + 1;
  2995.     }
  2996.     Rectangle (Nlm_currentHDC, rtool.left, rtool.top, rtool.right, rtool.bottom);
  2997.     if (oldPen != NULL) {
  2998.       SelectObject (Nlm_currentHDC, oldPen);
  2999.     }
  3000.   }
  3001. #endif
  3002. #ifdef WIN_X
  3003.   Nlm_RectTool  rtool;
  3004.  
  3005.   if (r != NULL && Nlm_currentXDisplay != NULL &&
  3006.       Nlm_currentXWindow != 0 && Nlm_currentXGC != NULL) {
  3007.     Nlm_RecTToRectTool (r, &rtool);
  3008.     rtool.width = MAX (rtool.width, 1);
  3009.     rtool.height = MAX (rtool.height, 1);
  3010.     XFillRectangle (Nlm_currentXDisplay, Nlm_currentXWindow, Nlm_currentXGC,
  3011.                     rtool.x - Nlm_XOffset, rtool.y - Nlm_YOffset,
  3012.                     rtool.width, rtool.height);
  3013.   }
  3014. #endif
  3015. }
  3016.  
  3017. extern void Nlm_InvertRect (Nlm_RectPtr r)
  3018.  
  3019. {
  3020. #ifdef WIN_MAC
  3021.   Nlm_RectTool  rtool;
  3022.  
  3023.   if (r != NULL) {
  3024.     Nlm_RecTToRectTool (r, &rtool);
  3025.     InvertRect (&rtool);
  3026.   }
  3027. #endif
  3028. #ifdef WIN_MSWIN
  3029.   Nlm_RectTool  rtool;
  3030.  
  3031.   if (r != NULL && Nlm_currentHDC != NULL) {
  3032.     Nlm_RecTToRectTool (r, &rtool);
  3033.     InvertRect (Nlm_currentHDC, &rtool);
  3034.   }
  3035. #endif
  3036. #ifdef WIN_X
  3037.   Nlm_RectTool  rtool;
  3038.  
  3039.   if (r != NULL && Nlm_currentXDisplay != NULL &&
  3040.       Nlm_currentXWindow != 0 && Nlm_currentXGC != NULL) {
  3041.     Nlm_RecTToRectTool (r, &rtool);
  3042. #ifdef DCLAP
  3043.         {
  3044.            /* method recommeded by XLib book, vol1/sect7.4.3 */
  3045.         Nlm_Uint4 xorcolor= Nlm_XforeColor ^ Nlm_XbackColor;
  3046.         XSetForeground( Nlm_currentXDisplay,Nlm_currentXGC, xorcolor);
  3047.     XSetFunction (Nlm_currentXDisplay, Nlm_currentXGC, GXxor);
  3048.         }
  3049. #else
  3050.     if (hasColor) {
  3051.       XSetFunction (Nlm_currentXDisplay, Nlm_currentXGC, GXequiv);
  3052.     } 
  3053.     else {
  3054.       XSetFunction (Nlm_currentXDisplay, Nlm_currentXGC, GXinvert);
  3055.     }
  3056. #endif
  3057.     XSetFillStyle (Nlm_currentXDisplay, Nlm_currentXGC, FillStippled);
  3058.     XFillRectangle (Nlm_currentXDisplay, Nlm_currentXWindow, Nlm_currentXGC,
  3059.                     rtool.x - Nlm_XOffset, rtool.y - Nlm_YOffset,
  3060.                     rtool.width, rtool.height);
  3061.     XSetFunction (Nlm_currentXDisplay, Nlm_currentXGC, currentFunction);
  3062.     XSetFillStyle (Nlm_currentXDisplay, Nlm_currentXGC, currentFillStyle);
  3063. #ifdef DCLAP
  3064.         XSetForeground( Nlm_currentXDisplay,Nlm_currentXGC, Nlm_XforeColor);
  3065. #endif
  3066.   }
  3067. #endif
  3068. }
  3069.  
  3070. extern void Nlm_ScrollRect (Nlm_RectPtr r, Nlm_IntD dx, Nlm_IntD dy)
  3071.  
  3072. {
  3073. #ifdef WIN_MAC
  3074.   Nlm_RectTool  rtool;
  3075.  
  3076.   if (r != NULL) {
  3077.     Nlm_RecTToRectTool (r, &rtool);
  3078.     ScrollRect (&rtool, dx, dy, (Nlm_RgnTool) Nlm_scrollRgn);
  3079.     InvalRgn ((Nlm_RgnTool) Nlm_scrollRgn);
  3080.   }
  3081. #endif
  3082. #ifdef WIN_MSWIN
  3083.   Nlm_RectTool  rtool;
  3084.  
  3085.   if (r != NULL && Nlm_currentHDC != NULL) {
  3086.     SetRectRgn ((Nlm_RgnTool) Nlm_scrollRgn, 0, 0, 0, 0);
  3087.     Nlm_RecTToRectTool (r, &rtool);
  3088.     ScrollDC (Nlm_currentHDC, dx, dy, &rtool, &rtool,
  3089.               (Nlm_RgnTool) Nlm_scrollRgn, NULL);
  3090.     if (Nlm_currentHWnd != NULL && Nlm_scrollRgn != NULL) {
  3091.       FillRgn (Nlm_currentHDC, (Nlm_RgnTool) Nlm_scrollRgn,
  3092.                GetBackgroundBrush (Nlm_currentHWnd));
  3093.     }
  3094.     InvalidateRgn (Nlm_currentHWnd, (Nlm_RgnTool) Nlm_scrollRgn, TRUE);
  3095.   }
  3096. #endif
  3097. #ifdef WIN_X
  3098.   XEvent        event;
  3099.   unsigned int  height;
  3100.   Nlm_RecT      rct;
  3101.   Nlm_RectTool  rtool;
  3102.   unsigned int  width;
  3103.   unsigned int  dstX;
  3104.   unsigned int  dstY;
  3105.   unsigned int  srcX;
  3106.   unsigned int  srcY;
  3107.  
  3108.   if (r != NULL && Nlm_currentXDisplay != NULL &&
  3109.       Nlm_currentXGC != NULL && Nlm_currentXWindow != 0) {
  3110.     height = ABS (r->bottom - r->top) - ABS (dy);
  3111.     width = ABS (r->right - r->left) - ABS (dx);
  3112.     if (dx > 0) {
  3113.       srcX = r->left - Nlm_XOffset;
  3114.       dstX = r->left - Nlm_XOffset + dx;
  3115.     } else if (dx < 0) {
  3116.       srcX = r->left - Nlm_XOffset - dx;
  3117.       dstX = r->left - Nlm_XOffset;
  3118.     } else {
  3119.       srcX = r->left - Nlm_XOffset;
  3120.       dstX = r->left - Nlm_XOffset;
  3121.     }
  3122.     if (dy > 0) {
  3123.       srcY = r->top - Nlm_YOffset;
  3124.       dstY = r->top - Nlm_YOffset + dy;
  3125.     } else if (dy < 0) {
  3126.       srcY = r->top - Nlm_YOffset - dy;
  3127.       dstY = r->top - Nlm_YOffset;
  3128.     } else {
  3129.       srcY = r->top - Nlm_YOffset;
  3130.       dstY = r->top - Nlm_YOffset;
  3131.     }
  3132.     if (hasColor) {
  3133.       XSetForeground (Nlm_currentXDisplay, Nlm_currentXGC, currentBkColor);
  3134.     }
  3135.     XCopyArea (Nlm_currentXDisplay, Nlm_currentXWindow, Nlm_currentXWindow,
  3136.                Nlm_currentXGC, srcX, srcY, width, height, dstX, dstY);
  3137.     XSync (Nlm_currentXDisplay, FALSE);
  3138.     while (XCheckTypedWindowEvent (Nlm_currentXDisplay,
  3139.            Nlm_currentXWindow, GraphicsExpose, &event)) {
  3140.       XClearArea (Nlm_currentXDisplay, Nlm_currentXWindow,
  3141.                   event.xgraphicsexpose.x, event.xgraphicsexpose.y,
  3142.                   event.xgraphicsexpose.width, event.xgraphicsexpose.height,
  3143.                   TRUE);
  3144.     }
  3145.     if (dx > 0) {
  3146.       rct = *r;
  3147.       rct.right = rct.left + dx;
  3148.       Nlm_RecTToRectTool (&rct, &rtool);
  3149.       XClearArea (Nlm_currentXDisplay, Nlm_currentXWindow,
  3150.                   rtool.x - Nlm_XOffset, rtool.y - Nlm_YOffset,
  3151.                   rtool.width, rtool.height, TRUE);
  3152.     } else if (dx < 0) {
  3153.       rct = *r;
  3154.       rct.left = rct.right + dx;
  3155.       Nlm_RecTToRectTool (&rct, &rtool);
  3156.       XClearArea (Nlm_currentXDisplay, Nlm_currentXWindow,
  3157.                   rtool.x - Nlm_XOffset, rtool.y - Nlm_YOffset,
  3158.                   rtool.width, rtool.height, TRUE);
  3159.     }
  3160.     if (dy > 0) {
  3161.       rct = *r;
  3162.       rct.bottom = rct.top + dy;
  3163.       Nlm_RecTToRectTool (&rct, &rtool);
  3164.       XClearArea (Nlm_currentXDisplay, Nlm_currentXWindow,
  3165.                   rtool.x - Nlm_XOffset, rtool.y - Nlm_YOffset,
  3166.                   rtool.width, rtool.height, TRUE);
  3167.     } else if (dy < 0) {
  3168.       rct = *r;
  3169.       rct.top = rct.bottom + dy;
  3170.       Nlm_RecTToRectTool (&rct, &rtool);
  3171.       XClearArea (Nlm_currentXDisplay, Nlm_currentXWindow,
  3172.                   rtool.x - Nlm_XOffset, rtool.y - Nlm_YOffset,
  3173.                   rtool.width, rtool.height, TRUE);
  3174.     }
  3175.     if (hasColor) {
  3176.       XSetForeground (Nlm_currentXDisplay, Nlm_currentXGC, currentFgColor);
  3177.     }
  3178.   }
  3179. #endif
  3180. }
  3181.  
  3182. extern void Nlm_EraseOval (Nlm_RectPtr r)
  3183.  
  3184. {
  3185. #ifdef WIN_MAC
  3186.   Nlm_RectTool  rtool;
  3187.  
  3188.   if (r != NULL) {
  3189.     Nlm_RecTToRectTool (r, &rtool);
  3190.     EraseOval (&rtool);
  3191.   }
  3192. #endif
  3193. #ifdef WIN_MSWIN
  3194.   HBRUSH  oldBrush;
  3195.   HPEN    oldPen;
  3196.  
  3197.   if (r != NULL && Nlm_currentHDC != NULL && Nlm_currentHWnd != NULL) {
  3198.     oldPen = SelectObject (Nlm_currentHDC, GetStockObject (NULL_PEN));
  3199.     oldBrush = SelectObject (Nlm_currentHDC, GetBackgroundBrush (Nlm_currentHWnd));
  3200.     Ellipse (Nlm_currentHDC, r->left, r->top, r->right, r->bottom);
  3201.     if (oldPen != NULL) {
  3202.       SelectObject (Nlm_currentHDC, oldPen);
  3203.     }
  3204.     if (oldBrush != NULL) {
  3205.       SelectObject (Nlm_currentHDC, oldBrush);
  3206.     }
  3207.   }
  3208. #endif
  3209. #ifdef WIN_X
  3210. #endif
  3211. }
  3212.  
  3213. extern void Nlm_FrameOval (Nlm_RectPtr r)
  3214.  
  3215. {
  3216. #ifdef WIN_MAC
  3217.   Nlm_RectTool  rtool;
  3218.  
  3219.   if (r != NULL) {
  3220.     Nlm_RecTToRectTool (r, &rtool);
  3221.     FrameOval (&rtool);
  3222.   }
  3223. #endif
  3224. #ifdef WIN_MSWIN
  3225.   HBRUSH  oldBrush;
  3226.  
  3227.   if (r != NULL && Nlm_currentHDC != NULL) {
  3228.     oldBrush = SelectObject (Nlm_currentHDC, GetStockObject (NULL_BRUSH));
  3229.     Ellipse (Nlm_currentHDC, r->left, r->top, r->right, r->bottom);
  3230.     if (oldBrush != NULL) {
  3231.       SelectObject (Nlm_currentHDC, oldBrush);
  3232.     }
  3233.   }
  3234. #endif
  3235. #ifdef WIN_X
  3236.   Nlm_RectTool  rtool;
  3237.  
  3238.   if (r != NULL && Nlm_currentXDisplay != NULL &&
  3239.       Nlm_currentXWindow != 0 && Nlm_currentXGC != NULL) {
  3240.     Nlm_RecTToRectTool (r, &rtool);
  3241.     XDrawArc (Nlm_currentXDisplay, Nlm_currentXWindow, Nlm_currentXGC,
  3242.               rtool.x - Nlm_XOffset, rtool.y - Nlm_YOffset,
  3243.               rtool.width - 1, rtool.height - 1, 0, 23040);
  3244.   }
  3245. #endif
  3246. }
  3247.  
  3248. extern void Nlm_PaintOval (Nlm_RectPtr r)
  3249.  
  3250. {
  3251. #ifdef WIN_MAC
  3252.   Nlm_RectTool  rtool;
  3253.  
  3254.   if (r != NULL) {
  3255.     Nlm_RecTToRectTool (r, &rtool);
  3256.     PaintOval (&rtool);
  3257.   }
  3258. #endif
  3259. #ifdef WIN_MSWIN
  3260.   HPEN  oldPen;
  3261.  
  3262.   if (r != NULL && Nlm_currentHDC != NULL) {
  3263.     oldPen = SelectObject (Nlm_currentHDC, GetStockObject (NULL_PEN));
  3264.     Ellipse (Nlm_currentHDC, r->left, r->top, r->right, r->bottom);
  3265.     if (oldPen != NULL) {
  3266.       SelectObject (Nlm_currentHDC, oldPen);
  3267.     }
  3268.   }
  3269. #endif
  3270. #ifdef WIN_X
  3271.   Nlm_RectTool  rtool;
  3272.  
  3273.   if (r != NULL && Nlm_currentXDisplay != NULL &&
  3274.       Nlm_currentXWindow != 0 && Nlm_currentXGC != NULL) {
  3275.     Nlm_RecTToRectTool (r, &rtool);
  3276.     XFillArc (Nlm_currentXDisplay, Nlm_currentXWindow, Nlm_currentXGC,
  3277.               rtool.x - Nlm_XOffset, rtool.y - Nlm_YOffset,
  3278.               rtool.width, rtool.height, 0, 23040);
  3279.   }
  3280. #endif
  3281. }
  3282.  
  3283. extern void Nlm_InvertOval (Nlm_RectPtr r)
  3284.  
  3285. {
  3286. #ifdef WIN_MAC
  3287.   Nlm_RectTool  rtool;
  3288.  
  3289.   if (r != NULL) {
  3290.     Nlm_RecTToRectTool (r, &rtool);
  3291.     InvertOval (&rtool);
  3292.   }
  3293. #endif
  3294. #ifdef WIN_MSWIN
  3295.   HBRUSH    oldBrush;
  3296.   Nlm_Int2  oldMode;
  3297.   HPEN      oldPen;
  3298.  
  3299.   if (r != NULL && Nlm_currentHDC != NULL) {
  3300.     oldPen = SelectObject (Nlm_currentHDC, GetStockObject (BLACK_PEN));
  3301.     oldBrush = SelectObject (Nlm_currentHDC, GetStockObject (BLACK_BRUSH));
  3302.     oldMode = GetROP2 (Nlm_currentHDC);
  3303.     SetROP2 (Nlm_currentHDC, R2_NOTXORPEN);
  3304.     Ellipse (Nlm_currentHDC, r->left, r->top, r->right, r->bottom);
  3305.     if (oldPen != NULL) {
  3306.       SelectObject (Nlm_currentHDC, oldPen);
  3307.     }
  3308.     if (oldBrush != NULL) {
  3309.       SelectObject (Nlm_currentHDC, oldBrush);
  3310.     }
  3311.     SetROP2 (Nlm_currentHDC, oldMode);
  3312.   }
  3313. #endif
  3314. #ifdef WIN_X
  3315. #endif
  3316. }
  3317.  
  3318. extern void Nlm_EraseRoundRect (Nlm_RectPtr r, Nlm_Int2 ovlWid,
  3319.                                 Nlm_Int2 ovlHgt)
  3320.  
  3321. {
  3322. #ifdef WIN_MAC
  3323.   Nlm_RectTool  rtool;
  3324.  
  3325.   if (r != NULL) {
  3326.     Nlm_RecTToRectTool (r, &rtool);
  3327.     EraseRoundRect (&rtool, ovlWid, ovlHgt);
  3328.   }
  3329. #endif
  3330. #ifdef WIN_MSWIN
  3331.   HBRUSH  oldBrush;
  3332.   HPEN    oldPen;
  3333.  
  3334.   if (r != NULL && Nlm_currentHDC != NULL && Nlm_currentHWnd != NULL) {
  3335.     oldPen = SelectObject (Nlm_currentHDC, GetStockObject (NULL_PEN));
  3336.     oldBrush = SelectObject (Nlm_currentHDC, GetBackgroundBrush (Nlm_currentHWnd));
  3337.     RoundRect (Nlm_currentHDC, r->left, r->top, r->right, r->bottom, ovlWid, ovlHgt);
  3338.     if (oldPen != NULL) {
  3339.       SelectObject (Nlm_currentHDC, oldPen);
  3340.     }
  3341.     if (oldBrush != NULL) {
  3342.       SelectObject (Nlm_currentHDC, oldBrush);
  3343.     }
  3344.   }
  3345. #endif
  3346. #ifdef WIN_X
  3347. #endif
  3348. }
  3349.  
  3350. extern void Nlm_FrameRoundRect (Nlm_RectPtr r, Nlm_Int2 ovlWid,
  3351.                                 Nlm_Int2 ovlHgt)
  3352.  
  3353. {
  3354. #ifdef WIN_MAC
  3355.   Nlm_RectTool  rtool;
  3356.  
  3357.   if (r != NULL) {
  3358.     Nlm_RecTToRectTool (r, &rtool);
  3359.     FrameRoundRect (&rtool, ovlWid, ovlHgt);
  3360.   }
  3361. #endif
  3362. #ifdef WIN_MSWIN
  3363.   HBRUSH  oldBrush;
  3364.  
  3365.   if (r != NULL && Nlm_currentHDC != NULL) {
  3366.     oldBrush = SelectObject (Nlm_currentHDC, GetStockObject (NULL_BRUSH));
  3367.     RoundRect (Nlm_currentHDC, r->left, r->top, r->right, r->bottom, ovlWid, ovlHgt);
  3368.     if (oldBrush != NULL) {
  3369.       SelectObject (Nlm_currentHDC, oldBrush);
  3370.     }
  3371.   }
  3372. #endif
  3373. #ifdef WIN_X
  3374. #endif
  3375. }
  3376.  
  3377. extern void Nlm_PaintRoundRect (Nlm_RectPtr r, Nlm_Int2 ovlWid,
  3378.                                 Nlm_Int2 ovlHgt)
  3379.  
  3380. {
  3381. #ifdef WIN_MAC
  3382.   Nlm_RectTool  rtool;
  3383.  
  3384.   if (r != NULL) {
  3385.     Nlm_RecTToRectTool (r, &rtool);
  3386.     PaintRoundRect (&rtool, ovlWid, ovlHgt);
  3387.   }
  3388. #endif
  3389. #ifdef WIN_MSWIN
  3390.   HPEN  oldPen;
  3391.  
  3392.   if (r != NULL && Nlm_currentHDC != NULL) {
  3393.     oldPen = SelectObject (Nlm_currentHDC, GetStockObject (NULL_PEN));
  3394.     RoundRect (Nlm_currentHDC, r->left, r->top, r->right, r->bottom, ovlWid, ovlHgt);
  3395.     if (oldPen != NULL) {
  3396.       SelectObject (Nlm_currentHDC, oldPen);
  3397.     }
  3398.   }
  3399. #endif
  3400. #ifdef WIN_X
  3401. #endif
  3402. }
  3403.  
  3404. extern void Nlm_InvertRoundRect (Nlm_RectPtr r, Nlm_Int2 ovlWid,
  3405.                                  Nlm_Int2 ovlHgt)
  3406.  
  3407. {
  3408. #ifdef WIN_MAC
  3409.   Nlm_RectTool  rtool;
  3410.  
  3411.   if (r != NULL) {
  3412.     Nlm_RecTToRectTool (r, &rtool);
  3413.     InvertRoundRect (&rtool, ovlWid, ovlHgt);
  3414.   }
  3415. #endif
  3416. #ifdef WIN_MSWIN
  3417.   HBRUSH    oldBrush;
  3418.   Nlm_Int2  oldMode;
  3419.   HPEN      oldPen;
  3420.  
  3421.   if (r != NULL && Nlm_currentHDC != NULL) {
  3422.     oldPen = SelectObject (Nlm_currentHDC, GetStockObject (BLACK_PEN));
  3423.     oldBrush = SelectObject (Nlm_currentHDC, GetStockObject (BLACK_BRUSH));
  3424.     oldMode = GetROP2 (Nlm_currentHDC);
  3425.     SetROP2 (Nlm_currentHDC, R2_NOTXORPEN);
  3426.     RoundRect (Nlm_currentHDC, r->left, r->top, r->right, r->bottom, ovlWid, ovlHgt);
  3427.     if (oldPen != NULL) {
  3428.       SelectObject (Nlm_currentHDC, oldPen);
  3429.     }
  3430.     if (oldBrush != NULL) {
  3431.       SelectObject (Nlm_currentHDC, oldBrush);
  3432.     }
  3433.     SetROP2 (Nlm_currentHDC, oldMode);
  3434.   }
  3435. #endif
  3436. #ifdef WIN_X
  3437. #endif
  3438. }
  3439.  
  3440. #ifdef WIN_X
  3441. static int Nlm_PtToAngle (Nlm_RectPtr r, Nlm_PoinT pt)
  3442.  
  3443. {
  3444.   int     rsult;
  3445.   double  val;
  3446.   double  x;
  3447.   double  y;
  3448.  
  3449.   x = pt.x - (r->right + r->left) / 2;
  3450.   y = (r->bottom + r->top) / 2 - pt.y;
  3451.   if (x == 0) {
  3452.     rsult = 5760;
  3453.   } else if (y == 0) {
  3454.     rsult = 0;
  3455.   } else {
  3456.     val = atan2 (ABS (y), ABS (x));
  3457.     rsult = val * 11520.0 / 3.14159;
  3458.   }
  3459.   if (x < 0) {
  3460.     if (y < 0) {
  3461.       rsult = 11520 + rsult;
  3462.     } else {
  3463.       rsult = 11520 - rsult;
  3464.     }
  3465.   } else if (y < 0) {
  3466.     rsult = 23040 - rsult;
  3467.   }
  3468.   return rsult;
  3469. }
  3470. #endif
  3471.  
  3472. extern void Nlm_EraseArc (Nlm_RectPtr r, Nlm_PoinT start, Nlm_PoinT end)
  3473.  
  3474. {
  3475. #ifdef WIN_MAC
  3476.   Nlm_Int2       angle1;
  3477.   Nlm_Int2       angle2;
  3478.   Nlm_Int2       arcAngle;
  3479.   Nlm_PointTool  ptool1;
  3480.   Nlm_PointTool  ptool2;
  3481.   Nlm_RectTool   rtool;
  3482.  
  3483.   if (r != NULL) {
  3484.     Nlm_RecTToRectTool (r, &rtool);
  3485.     Nlm_PoinTToPointTool (start, &ptool1);
  3486.     Nlm_PoinTToPointTool (end, &ptool2);
  3487.     PtToAngle (&rtool, ptool1, &angle1);
  3488.     PtToAngle (&rtool, ptool2, &angle2);
  3489.     if (angle2 > angle1) {
  3490.       arcAngle = angle2 - angle1;
  3491.     } else {
  3492.       arcAngle = 360 - angle1 + angle2;
  3493.     }
  3494.     EraseArc (&rtool, angle1, arcAngle);
  3495.   }
  3496. #endif
  3497. #ifdef WIN_MSWIN
  3498.   HBRUSH  oldBrush;
  3499.   HPEN    oldPen;
  3500.  
  3501.   if (r != NULL && Nlm_currentHDC != NULL && Nlm_currentHWnd != NULL) {
  3502.     oldPen = SelectObject (Nlm_currentHDC, GetStockObject (NULL_PEN));
  3503.     oldBrush = SelectObject (Nlm_currentHDC, GetBackgroundBrush (Nlm_currentHWnd));
  3504.     Pie (Nlm_currentHDC, r->left, r->top, r->right, r->bottom,
  3505.          end.x, end.y, start.x, start.y);
  3506.     if (oldPen != NULL) {
  3507.       SelectObject (Nlm_currentHDC, oldPen);
  3508.     }
  3509.     if (oldBrush != NULL) {
  3510.       SelectObject (Nlm_currentHDC, oldBrush);
  3511.     }
  3512.   }
  3513. #endif
  3514. #ifdef WIN_X
  3515. #endif
  3516. }
  3517.  
  3518. extern void Nlm_FrameArc (Nlm_RectPtr r, Nlm_PoinT start, Nlm_PoinT end)
  3519. {
  3520. #ifdef WIN_MAC
  3521.   Nlm_Int2       angle1;
  3522.   Nlm_Int2       angle2;
  3523.   Nlm_Int2       arcAngle;
  3524.   Nlm_PointTool  ptool1;
  3525.   Nlm_PointTool  ptool2;
  3526.   Nlm_RectTool   rtool;
  3527.  
  3528.   if (r != NULL) {
  3529.     Nlm_RecTToRectTool (r, &rtool);
  3530.     Nlm_PoinTToPointTool (start, &ptool1);
  3531.     Nlm_PoinTToPointTool (end, &ptool2);
  3532.     PtToAngle (&rtool, ptool1, &angle1);
  3533.     PtToAngle (&rtool, ptool2, &angle2);
  3534.     if (angle2 > angle1) {
  3535.       arcAngle = angle2 - angle1;
  3536.     } else {
  3537.       arcAngle = 360 - angle1 + angle2;
  3538.     }
  3539.     FrameArc (&rtool, angle1, arcAngle);
  3540.   }
  3541. #endif
  3542. #ifdef WIN_MSWIN
  3543.   HPEN  oldPen;
  3544.  
  3545.   if (r != NULL && Nlm_currentHDC != NULL) {
  3546.     oldPen = SelectObject (Nlm_currentHDC, GetStockObject (NULL_PEN));
  3547.     Arc (Nlm_currentHDC, r->left, r->top, r->right, r->bottom,
  3548.          end.x, end.y, start.x, start.y);
  3549.     if (oldPen != NULL) {
  3550.       SelectObject (Nlm_currentHDC, oldPen);
  3551.     }
  3552.   }
  3553. #endif
  3554. #ifdef WIN_X
  3555.   int           angle1;
  3556.   int           angle2;
  3557.   int           arcAngle;
  3558.   Nlm_RectTool  rtool;
  3559.  
  3560.   if (r != NULL && Nlm_currentXDisplay != NULL &&
  3561.       Nlm_currentXWindow != 0 && Nlm_currentXGC != NULL) {
  3562.     Nlm_RecTToRectTool (r, &rtool);
  3563.     angle1 = Nlm_PtToAngle (r, start);
  3564.     angle2 = Nlm_PtToAngle (r, end);
  3565.     if (angle1 > angle2) {
  3566.       arcAngle = angle1 - angle2;
  3567.       XDrawArc (Nlm_currentXDisplay, Nlm_currentXWindow, Nlm_currentXGC,
  3568.                 rtool.x - Nlm_XOffset, rtool.y - Nlm_YOffset,
  3569.                 rtool.width - 1, rtool.height - 1, angle1, -arcAngle);
  3570.     } else {
  3571.       arcAngle = 23040 - angle2 + angle1;
  3572.       XDrawArc (Nlm_currentXDisplay, Nlm_currentXWindow, Nlm_currentXGC,
  3573.                 rtool.x - Nlm_XOffset, rtool.y - Nlm_YOffset,
  3574.                 rtool.width - 1, rtool.height - 1, angle1, -arcAngle);
  3575.     }
  3576.   }
  3577. #endif
  3578. }
  3579.  
  3580. extern void Nlm_PaintArc (Nlm_RectPtr r, Nlm_PoinT start, Nlm_PoinT end)
  3581.  
  3582. {
  3583. #ifdef WIN_MAC
  3584.   Nlm_Int2       angle1;
  3585.   Nlm_Int2       angle2;
  3586.   Nlm_Int2       arcAngle;
  3587.   Nlm_PointTool  ptool1;
  3588.   Nlm_PointTool  ptool2;
  3589.   Nlm_RectTool   rtool;
  3590.  
  3591.   if (r != NULL) {
  3592.     Nlm_RecTToRectTool (r, &rtool);
  3593.     Nlm_PoinTToPointTool (start, &ptool1);
  3594.     Nlm_PoinTToPointTool (end, &ptool2);
  3595.     PtToAngle (&rtool, ptool1, &angle1);
  3596.     PtToAngle (&rtool, ptool2, &angle2);
  3597.     if (angle2 > angle1) {
  3598.       arcAngle = angle2 - angle1;
  3599.     } else {
  3600.       arcAngle = 360 - angle1 + angle2;
  3601.     }
  3602.     PaintArc (&rtool, angle1, arcAngle);
  3603.   }
  3604. #endif
  3605. #ifdef WIN_MSWIN
  3606.   HPEN  oldPen;
  3607.  
  3608.   if (r != NULL && Nlm_currentHDC != NULL) {
  3609.     oldPen = SelectObject (Nlm_currentHDC, GetStockObject (NULL_PEN));
  3610.     Pie (Nlm_currentHDC, r->left, r->top, r->right, r->bottom,
  3611.          end.x, end.y, start.x, start.y);
  3612.     if (oldPen != NULL) {
  3613.       SelectObject (Nlm_currentHDC, oldPen);
  3614.     }
  3615.   }
  3616. #endif
  3617. #ifdef WIN_X
  3618.   int           angle1;
  3619.   int           angle2;
  3620.   int           arcAngle;
  3621.   Nlm_RectTool  rtool;
  3622.  
  3623.   if (r != NULL && Nlm_currentXDisplay != NULL &&
  3624.       Nlm_currentXWindow != 0 && Nlm_currentXGC != NULL) {
  3625.     Nlm_RecTToRectTool (r, &rtool);
  3626.     angle1 = Nlm_PtToAngle (r, start);
  3627.     angle2 = Nlm_PtToAngle (r, end);
  3628.     if (angle1 > angle2) {
  3629.       arcAngle = angle1 - angle2;
  3630.       XFillArc (Nlm_currentXDisplay, Nlm_currentXWindow, Nlm_currentXGC,
  3631.                 rtool.x - Nlm_XOffset, rtool.y - Nlm_YOffset,
  3632.                 rtool.width, rtool.height, angle1, -arcAngle);
  3633.     } else {
  3634.       arcAngle = 23040 - angle2 + angle1;
  3635.       XFillArc (Nlm_currentXDisplay, Nlm_currentXWindow, Nlm_currentXGC,
  3636.                 rtool.x - Nlm_XOffset, rtool.y - Nlm_YOffset,
  3637.                 rtool.width, rtool.height, angle1, -arcAngle);
  3638.     }
  3639.   }
  3640. #endif
  3641. }
  3642.  
  3643. extern void Nlm_InvertArc (Nlm_RectPtr r, Nlm_PoinT start, Nlm_PoinT end)
  3644.  
  3645. {
  3646. #ifdef WIN_MAC
  3647.   Nlm_Int2       angle1;
  3648.   Nlm_Int2       angle2;
  3649.   Nlm_Int2       arcAngle;
  3650.   Nlm_PointTool  ptool1;
  3651.   Nlm_PointTool  ptool2;
  3652.   Nlm_RectTool   rtool;
  3653.  
  3654.   if (r != NULL) {
  3655.     Nlm_RecTToRectTool (r, &rtool);
  3656.     Nlm_PoinTToPointTool (start, &ptool1);
  3657.     Nlm_PoinTToPointTool (end, &ptool2);
  3658.     PtToAngle (&rtool, ptool1, &angle1);
  3659.     PtToAngle (&rtool, ptool2, &angle2);
  3660.     if (angle2 > angle1) {
  3661.       arcAngle = angle2 - angle1;
  3662.     } else {
  3663.       arcAngle = 360 - angle1 + angle2;
  3664.     }
  3665.     InvertArc (&rtool, angle1, arcAngle);
  3666.   }
  3667. #endif
  3668. #ifdef WIN_MSWIN
  3669.   HBRUSH    oldBrush;
  3670.   Nlm_Int2  oldMode;
  3671.   HPEN      oldPen;
  3672.  
  3673.   if (r != NULL && Nlm_currentHDC != NULL) {
  3674.     oldPen = SelectObject (Nlm_currentHDC, GetStockObject (BLACK_PEN));
  3675.     oldBrush = SelectObject (Nlm_currentHDC, GetStockObject (BLACK_BRUSH));
  3676.     oldMode = GetROP2 (Nlm_currentHDC);
  3677.     SetROP2 (Nlm_currentHDC, R2_NOTXORPEN);
  3678.     Pie (Nlm_currentHDC, r->left, r->top, r->right, r->bottom,
  3679.          end.x, end.y, start.x, start.y);
  3680.     if (oldPen != NULL) {
  3681.       SelectObject (Nlm_currentHDC, oldPen);
  3682.     }
  3683.     if (oldBrush != NULL) {
  3684.       SelectObject (Nlm_currentHDC, oldBrush);
  3685.     }
  3686.     SetROP2 (Nlm_currentHDC, oldMode);
  3687.   }
  3688. #endif
  3689. #ifdef WIN_X
  3690. #endif
  3691. }
  3692.  
  3693. #ifdef WIN_MAC
  3694. static PolyHandle Nlm_CreatePoly (Nlm_Int2 num, Nlm_PointPtr pts)
  3695.  
  3696. {
  3697.   Nlm_PoinT   firstPt;
  3698.   Nlm_Int2    i;
  3699.   Nlm_PoinT   pt;
  3700.   PolyHandle  rsult;
  3701.  
  3702.   rsult = NULL;
  3703.   if (pts != NULL && num > 0) {
  3704.     rsult = OpenPoly ();
  3705.     firstPt = pts [0];
  3706.     MoveTo (firstPt.x, firstPt.y);
  3707.     for (i = 1; i < num; i++) {
  3708.       pt = pts [i];
  3709.       LineTo (pt.x, pt.y);
  3710.     }
  3711.     if (! Nlm_EqualPt (pt, firstPt)) {
  3712.       LineTo (firstPt.x, firstPt.y);
  3713.     }
  3714.     ClosePoly ();
  3715.   }
  3716.   return rsult;
  3717. }
  3718.  
  3719. static void Nlm_DestroyPoly (PolyHandle ply)
  3720.  
  3721. {
  3722.   if (ply != NULL) {
  3723.     KillPoly (ply);
  3724.   }
  3725. }
  3726. #endif
  3727.  
  3728. #ifdef WIN_MSWIN
  3729. static LPPOINT Nlm_CreatePoly (Nlm_Int2 num, Nlm_PointPtr pts)
  3730.  
  3731. {
  3732.   Nlm_PoinT      firstPt;
  3733.   Nlm_Int2       i;
  3734.   Nlm_PoinT      pt;
  3735.   Nlm_PointTool  ptool;
  3736.   LPPOINT        rsult;
  3737.  
  3738.   rsult = NULL;
  3739.   if (pts != NULL && num > 0) {
  3740.     rsult = (LPPOINT) Nlm_MemNew ((Nlm_sizeT) ((num + 1) * sizeof (POINT)));
  3741.     if (rsult != NULL) {
  3742.       firstPt = pts [0];
  3743.       for (i = 0; i < num; i++) {
  3744.         pt = pts [i];
  3745.         Nlm_PoinTToPointTool (pt, &ptool);
  3746.         rsult [i] = ptool;
  3747.       }
  3748.       if (! Nlm_EqualPt (pt, firstPt)) {
  3749.         Nlm_PoinTToPointTool (firstPt, &ptool);
  3750.         rsult [i] = ptool;
  3751.       }
  3752.     }
  3753.   }
  3754.   return rsult;
  3755. }
  3756.  
  3757. static void Nlm_DestroyPoly (LPPOINT ply)
  3758.  
  3759. {
  3760.   if (ply != NULL) {
  3761.     Nlm_MemFree (ply);
  3762.   }
  3763. }
  3764. #endif
  3765.  
  3766. #ifdef WIN_X
  3767. static XPoint *Nlm_CreatePoly (Nlm_Int2 num, Nlm_PointPtr pts)
  3768.  
  3769. {
  3770.   Nlm_PoinT      firstPt;
  3771.   Nlm_Int2       i;
  3772.   Nlm_PoinT      pt;
  3773.   Nlm_PointTool  ptool;
  3774.   XPoint         *rsult;
  3775.  
  3776.   rsult = NULL;
  3777.   if (pts != NULL && num > 0) {
  3778.     rsult = (XPoint *) Nlm_MemNew ((Nlm_sizeT) ((num + 1) * sizeof (XPoint)));
  3779.     if (rsult != NULL) {
  3780.       firstPt = pts [0];
  3781.       firstPt.x -= Nlm_XOffset;
  3782.       firstPt.y -= Nlm_YOffset;
  3783.       for (i = 0; i < num; i++) {
  3784.         pt = pts [i];
  3785.         pt.x -= Nlm_XOffset;
  3786.         pt.y -= Nlm_YOffset;
  3787.         Nlm_PoinTToPointTool (pt, &ptool);
  3788.         rsult [i] = ptool;
  3789.       }
  3790.       if (! Nlm_EqualPt (pt, firstPt)) {
  3791.         Nlm_PoinTToPointTool (firstPt, &ptool);
  3792.         rsult [i] = ptool;
  3793.       }
  3794.     }
  3795.   }
  3796.   return rsult;
  3797. }
  3798.  
  3799. static void Nlm_DestroyPoly (XPoint *ply)
  3800.  
  3801. {
  3802.   if (ply != NULL) {
  3803.     Nlm_MemFree (ply);
  3804.   }
  3805. }
  3806. #endif
  3807.  
  3808. extern void Nlm_ErasePoly (Nlm_Int2 num, Nlm_PointPtr pts)
  3809.  
  3810. {
  3811.   if (pts != NULL && num > 1) {
  3812. #ifdef WIN_MAC
  3813.   PolyHandle   ply;
  3814.  
  3815.   ply = Nlm_CreatePoly (num, pts);
  3816.   if (ply != NULL) {
  3817.     ErasePoly (ply);
  3818.   }
  3819.   Nlm_DestroyPoly (ply);
  3820. #endif
  3821. #ifdef WIN_MSWIN
  3822. #endif
  3823. #ifdef WIN_X
  3824. #endif
  3825.   }
  3826. }
  3827.  
  3828. extern void Nlm_FramePoly (Nlm_Int2 num, Nlm_PointPtr pts)
  3829.  
  3830. {
  3831.   if (pts != NULL && num > 1) {
  3832. #ifdef WIN_MAC
  3833.   PolyHandle   ply;
  3834.  
  3835.   ply = Nlm_CreatePoly (num, pts);
  3836.   if (ply != NULL) {
  3837.     FramePoly (ply);
  3838.   }
  3839.   Nlm_DestroyPoly (ply);
  3840. #endif
  3841. #ifdef WIN_MSWIN
  3842.   LPPOINT  ply;
  3843.  
  3844.   ply = Nlm_CreatePoly (num, pts);
  3845.   if (Nlm_currentHDC != NULL && ply != NULL) {
  3846.     if (! Nlm_EqualPt (pts [0], pts [num - 1])) {
  3847.       num++;
  3848.     }
  3849.     Polyline (Nlm_currentHDC, ply, num);
  3850.   }
  3851.   Nlm_DestroyPoly (ply);
  3852. #endif
  3853. #ifdef WIN_X
  3854.   XPoint  *ply;
  3855.  
  3856.   ply = Nlm_CreatePoly (num, pts);
  3857.   if (Nlm_currentXDisplay != NULL && Nlm_currentXWindow != 0 &&
  3858.       Nlm_currentXGC != NULL && ply != NULL) {
  3859.     if (! Nlm_EqualPt (pts [0], pts [num - 1])) {
  3860.       num++;
  3861.     }
  3862.     XDrawLines (Nlm_currentXDisplay, Nlm_currentXWindow, Nlm_currentXGC,
  3863.                 ply, num, CoordModeOrigin);
  3864.   }
  3865.   Nlm_DestroyPoly (ply);
  3866. #endif
  3867.   }
  3868. }
  3869.  
  3870. extern void Nlm_PaintPoly (Nlm_Int2 num, Nlm_PointPtr pts)
  3871.  
  3872. {
  3873.   if (pts != NULL && num > 1) {
  3874. #ifdef WIN_MAC
  3875.   PolyHandle   ply;
  3876.  
  3877.   ply = Nlm_CreatePoly (num, pts);
  3878.   if (ply != NULL) {
  3879.     PaintPoly (ply);
  3880.   }
  3881.   Nlm_DestroyPoly (ply);
  3882. #endif
  3883. #ifdef WIN_MSWIN
  3884.   LPPOINT  ply;
  3885.  
  3886.   ply = Nlm_CreatePoly (num, pts);
  3887.   if (Nlm_currentHDC != NULL && ply != NULL) {
  3888.     if (! Nlm_EqualPt (pts [0], pts [num - 1])) {
  3889.       num++;
  3890.     }
  3891.     SetPolyFillMode (Nlm_currentHDC, ALTERNATE);
  3892.     Polygon (Nlm_currentHDC, ply, num);
  3893.   }
  3894.   Nlm_DestroyPoly (ply);
  3895. #endif
  3896. #ifdef WIN_X
  3897.   XPoint  *ply;
  3898.  
  3899.   ply = Nlm_CreatePoly (num, pts);
  3900.   if (Nlm_currentXDisplay != NULL && Nlm_currentXWindow != 0 &&
  3901.       Nlm_currentXGC != NULL && ply != NULL) {
  3902.     if (! Nlm_EqualPt (pts [0], pts [num - 1])) {
  3903.       num++;
  3904.     }
  3905.     XSetFillRule (Nlm_currentXDisplay, Nlm_currentXGC, EvenOddRule);
  3906.     XFillPolygon (Nlm_currentXDisplay, Nlm_currentXWindow, Nlm_currentXGC,
  3907.                   ply, num, Complex, CoordModeOrigin);
  3908.   }
  3909.   Nlm_DestroyPoly (ply);
  3910. #endif
  3911.   }
  3912. }
  3913.  
  3914. extern void Nlm_InvertPoly (Nlm_Int2 num, Nlm_PointPtr pts)
  3915.  
  3916. {
  3917.   if (pts != NULL && num > 1) {
  3918. #ifdef WIN_MAC
  3919.   PolyHandle   ply;
  3920.  
  3921.   ply = Nlm_CreatePoly (num, pts);
  3922.   if (ply != NULL) {
  3923.     InvertPoly (ply);
  3924.   }
  3925.   Nlm_DestroyPoly (ply);
  3926. #endif
  3927. #ifdef WIN_MSWIN
  3928. #endif
  3929. #ifdef WIN_X
  3930. #endif
  3931.   }
  3932. }
  3933.  
  3934. extern Nlm_RegioN Nlm_CreateRgn (void)
  3935.  
  3936. {
  3937.   Nlm_RgnTool  ntool;
  3938.  
  3939. #ifdef WIN_MAC
  3940.   ntool = NewRgn ();
  3941. #endif
  3942. #ifdef WIN_MSWIN
  3943.   ntool = CreateRectRgn (0, 0, 0, 0);
  3944. #endif
  3945. #ifdef WIN_X
  3946.   ntool = XCreateRegion ();
  3947. #endif
  3948.   return (Nlm_RegioN) ntool;
  3949. }
  3950.  
  3951. extern Nlm_RegioN Nlm_DestroyRgn (Nlm_RegioN rgn)
  3952.  
  3953. {
  3954.   Nlm_RgnTool  ntool;
  3955.  
  3956.   if (rgn != NULL) {
  3957.     ntool = (Nlm_RgnTool) rgn;
  3958. #ifdef WIN_MAC
  3959.     DisposeRgn (ntool);
  3960. #endif
  3961. #ifdef WIN_MSWIN
  3962.     DeleteObject (ntool);
  3963. #endif
  3964. #ifdef WIN_X
  3965.     XDestroyRegion (ntool);
  3966. #endif
  3967.   }
  3968.   return NULL;
  3969. }
  3970.  
  3971. extern void Nlm_ClearRgn (Nlm_RegioN rgn)
  3972.  
  3973. {
  3974.   Nlm_RgnTool  ntool;
  3975.   Nlm_RgnTool  temp;
  3976.  
  3977.   if (rgn != NULL) {
  3978.     ntool = (Nlm_RgnTool) rgn;
  3979. #ifdef WIN_MAC
  3980.     SetEmptyRgn (ntool);
  3981. #endif
  3982. #ifdef WIN_MSWIN
  3983.     temp = CreateRectRgn (0, 0, 0, 0);
  3984.     CombineRgn (ntool, temp, temp, RGN_COPY);
  3985.     DeleteObject (temp);
  3986. #endif
  3987. #ifdef WIN_X
  3988.     XUnionRegion (emptyRgn, emptyRgn, ntool);
  3989. #endif
  3990.   } 
  3991. }
  3992.  
  3993. extern void Nlm_LoadRectRgn (Nlm_RegioN rgn, Nlm_IntD lf,
  3994.                              Nlm_IntD tp, Nlm_IntD rt,
  3995.                              Nlm_IntD bt)
  3996. {
  3997.   Nlm_RgnTool   ntool;
  3998. #ifdef WIN_X
  3999.   Nlm_RecT      rct;
  4000.   Nlm_RectTool  rtool;
  4001. #endif
  4002.  
  4003.   if (rgn != NULL) {
  4004.     ntool = (Nlm_RgnTool) rgn;
  4005. #ifdef WIN_MAC
  4006.     SetRectRgn (ntool, lf, tp, rt, bt);
  4007. #endif
  4008. #ifdef WIN_MSWIN
  4009.     SetRectRgn (ntool, lf, tp, rt, bt);
  4010. #endif
  4011. #ifdef WIN_X
  4012.     Nlm_LoadRect (&rct, lf, tp, rt, bt);
  4013.     Nlm_RecTToRectTool (&rct, &rtool);
  4014.     XUnionRectWithRegion (&rtool, emptyRgn, ntool);
  4015. #endif
  4016.   }
  4017. }
  4018.  
  4019. extern void Nlm_OffsetRgn (Nlm_RegioN rgn, Nlm_IntD dx, Nlm_IntD dy)
  4020.  
  4021. {
  4022.   Nlm_RgnTool  ntool;
  4023.  
  4024.   if (rgn != NULL) {
  4025.     ntool = (Nlm_RgnTool) rgn;
  4026. #ifdef WIN_MAC
  4027.     OffsetRgn (ntool, dx, dy);
  4028. #endif
  4029. #ifdef WIN_MSWIN
  4030.     OffsetRgn (ntool, dx, dy);
  4031. #endif
  4032. #ifdef WIN_X
  4033.     XOffsetRegion (ntool, dx, dy);
  4034. #endif
  4035.   }
  4036. }
  4037.  
  4038. extern void Nlm_SectRgn (Nlm_RegioN src1, Nlm_RegioN src2, Nlm_RegioN dst)
  4039.  
  4040. {
  4041.   Nlm_RgnTool  ntool1;
  4042.   Nlm_RgnTool  ntool2;
  4043.   Nlm_RgnTool  ntool3;
  4044. #ifdef WIN_X
  4045.   Nlm_RgnTool  temp;
  4046. #endif
  4047.  
  4048.   if (src1 != NULL && src2 != NULL && dst != NULL) {
  4049.     ntool1 = (Nlm_RgnTool) src1;
  4050.     ntool2 = (Nlm_RgnTool) src2;
  4051.     ntool3 = (Nlm_RgnTool) dst;
  4052. #ifdef WIN_MAC
  4053.     SectRgn (ntool1, ntool2, ntool3);
  4054. #endif
  4055. #ifdef WIN_MSWIN
  4056.     CombineRgn (ntool3, ntool1, ntool2, RGN_AND);
  4057. #endif
  4058. #ifdef WIN_X
  4059.     temp = XCreateRegion ();
  4060.     XIntersectRegion (ntool1, ntool2, temp);
  4061.     XUnionRegion (temp, emptyRgn, ntool3);
  4062.     XDestroyRegion (temp);
  4063. #endif
  4064.   }
  4065. }
  4066.  
  4067. extern void Nlm_UnionRgn (Nlm_RegioN src1, Nlm_RegioN src2, Nlm_RegioN dst)
  4068.  
  4069. {
  4070.   Nlm_RgnTool  ntool1;
  4071.   Nlm_RgnTool  ntool2;
  4072.   Nlm_RgnTool  ntool3;
  4073. #ifdef WIN_X
  4074.   Nlm_RgnTool  temp;
  4075. #endif
  4076.  
  4077.   if (src1 != NULL && src2 != NULL && dst != NULL) {
  4078.     ntool1 = (Nlm_RgnTool) src1;
  4079.     ntool2 = (Nlm_RgnTool) src2;
  4080.     ntool3 = (Nlm_RgnTool) dst;
  4081. #ifdef WIN_MAC
  4082.     UnionRgn (ntool1, ntool2, ntool3);
  4083. #endif
  4084. #ifdef WIN_MSWIN
  4085.     CombineRgn (ntool3, ntool1, ntool2, RGN_OR);
  4086. #endif
  4087. #ifdef WIN_X
  4088.     temp = XCreateRegion ();
  4089.     XUnionRegion (ntool1, ntool2, temp);
  4090.     XUnionRegion (temp, emptyRgn, ntool3);
  4091.     XDestroyRegion (temp);
  4092. #endif
  4093.   }
  4094. }
  4095.  
  4096. extern void Nlm_DiffRgn (Nlm_RegioN src1, Nlm_RegioN src2, Nlm_RegioN dst)
  4097.  
  4098. {
  4099.   Nlm_RgnTool  ntool1;
  4100.   Nlm_RgnTool  ntool2;
  4101.   Nlm_RgnTool  ntool3;
  4102. #ifdef WIN_X
  4103.   Nlm_RgnTool  temp;
  4104. #endif
  4105.  
  4106.   if (src1 != NULL && src2 != NULL && dst != NULL) {
  4107.     ntool1 = (Nlm_RgnTool) src1;
  4108.     ntool2 = (Nlm_RgnTool) src2;
  4109.     ntool3 = (Nlm_RgnTool) dst;
  4110. #ifdef WIN_MAC
  4111.     DiffRgn (ntool1, ntool2, ntool3);
  4112. #endif
  4113. #ifdef WIN_MSWIN
  4114.     CombineRgn (ntool3, ntool1, ntool2, RGN_DIFF);
  4115. #endif
  4116. #ifdef WIN_X
  4117.     temp = XCreateRegion ();
  4118.     XSubtractRegion (ntool1, ntool2, temp);
  4119.     XUnionRegion (temp, emptyRgn, ntool3);
  4120.     XDestroyRegion (temp);
  4121. #endif
  4122.   }
  4123. }
  4124.  
  4125. extern void Nlm_XorRgn (Nlm_RegioN src1, Nlm_RegioN src2, Nlm_RegioN dst)
  4126.  
  4127. {
  4128.   Nlm_RgnTool  ntool1;
  4129.   Nlm_RgnTool  ntool2;
  4130.   Nlm_RgnTool  ntool3;
  4131. #ifdef WIN_X
  4132.   Nlm_RgnTool  temp;
  4133. #endif
  4134.  
  4135.   if (src1 != NULL && src2 != NULL && dst != NULL) {
  4136.     ntool1 = (Nlm_RgnTool) src1;
  4137.     ntool2 = (Nlm_RgnTool) src2;
  4138.     ntool3 = (Nlm_RgnTool) dst;
  4139. #ifdef WIN_MAC
  4140.     XorRgn (ntool1, ntool2, ntool3);
  4141. #endif
  4142. #ifdef WIN_MSWIN
  4143.     CombineRgn (ntool3, ntool1, ntool2, RGN_XOR);
  4144. #endif
  4145. #ifdef WIN_X
  4146.     temp = XCreateRegion ();
  4147.     XXorRegion (ntool1, ntool2, temp);
  4148.     XUnionRegion (temp, emptyRgn, ntool3);
  4149.     XDestroyRegion (temp);
  4150. #endif
  4151.   }
  4152. }
  4153.  
  4154. extern Nlm_Boolean Nlm_EqualRgn (Nlm_RegioN rgn1, Nlm_RegioN rgn2)
  4155.  
  4156. {
  4157.   Nlm_RgnTool  ntool1;
  4158.   Nlm_RgnTool  ntool2;
  4159.   Nlm_Boolean  rsult;
  4160.  
  4161.   rsult = FALSE;
  4162.   if (rgn1 != NULL && rgn2 != NULL) {
  4163.     ntool1 = (Nlm_RgnTool) rgn1;
  4164.     ntool2 = (Nlm_RgnTool) rgn2;
  4165. #ifdef WIN_MAC
  4166.     rsult = EqualRgn (ntool1, ntool2);
  4167. #endif
  4168. #ifdef WIN_MSWIN
  4169.     rsult = (Nlm_Boolean) EqualRgn (ntool1, ntool2);
  4170. #endif
  4171. #ifdef WIN_X
  4172.     rsult = (XEqualRegion (ntool1, ntool2) != 0);
  4173. #endif
  4174.   }
  4175.   return rsult;
  4176. }
  4177.  
  4178. extern Nlm_Boolean Nlm_EmptyRgn (Nlm_RegioN rgn)
  4179.  
  4180. {
  4181.   Nlm_RgnTool   ntool;
  4182.   Nlm_Boolean   rsult;
  4183. #ifdef WIN_MSWIN
  4184.   Nlm_RectTool  rtool;
  4185. #endif
  4186.  
  4187.   rsult = FALSE;
  4188.   if (rgn != NULL) {
  4189.     ntool = (Nlm_RgnTool) rgn;
  4190. #ifdef WIN_MAC
  4191.     rsult = EmptyRgn (ntool);
  4192. #endif
  4193. #ifdef WIN_MSWIN
  4194.     rsult = (Nlm_Boolean) (GetRgnBox (ntool, &rtool) == NULLREGION);
  4195. #endif
  4196. #ifdef WIN_X
  4197.     rsult = (XEmptyRegion (ntool) != 0);
  4198. #endif
  4199.   }
  4200.   return rsult;
  4201. }
  4202.  
  4203. extern void Nlm_EraseRgn (Nlm_RegioN rgn)
  4204.  
  4205. {
  4206. #ifdef WIN_MAC
  4207.   Nlm_RgnTool  ntool;
  4208.  
  4209.   if (rgn != NULL) {
  4210.     ntool = (Nlm_RgnTool) rgn;
  4211.     EraseRgn (ntool);
  4212.   }
  4213. #endif
  4214. #ifdef WIN_MSWIN
  4215.   Nlm_RgnTool  ntool;
  4216.  
  4217.   if (rgn != NULL && Nlm_currentHDC != NULL && Nlm_currentHWnd != NULL) {
  4218.     ntool = (Nlm_RgnTool) rgn;
  4219.     FillRgn (Nlm_currentHDC, ntool, GetBackgroundBrush (Nlm_currentHWnd));
  4220.   }
  4221. #endif
  4222. #ifdef WIN_X
  4223. #endif
  4224. }
  4225.  
  4226. extern void Nlm_FrameRgn (Nlm_RegioN rgn)
  4227.  
  4228. {
  4229. #ifdef WIN_MAC
  4230.   Nlm_RgnTool  ntool;
  4231.  
  4232.   if (rgn != NULL) {
  4233.     ntool = (Nlm_RgnTool) rgn;
  4234.     FrameRgn (ntool);
  4235.   }
  4236. #endif
  4237. #ifdef WIN_MSWIN
  4238.   Nlm_RgnTool  ntool;
  4239.  
  4240.   if (rgn != NULL && Nlm_currentHDC != NULL) {
  4241.     ntool = (Nlm_RgnTool) rgn;
  4242.     FrameRgn (Nlm_currentHDC, ntool, GetStockObject (BLACK_BRUSH), 1, 1);
  4243.   }
  4244. #endif
  4245. #ifdef WIN_X
  4246. #endif
  4247. }
  4248.  
  4249. extern void Nlm_PaintRgn (Nlm_RegioN rgn)
  4250.  
  4251. {
  4252. #ifdef WIN_MAC
  4253.   Nlm_RgnTool  ntool;
  4254.  
  4255.   if (rgn != NULL) {
  4256.     ntool = (Nlm_RgnTool) rgn;
  4257.     PaintRgn (ntool);
  4258.   }
  4259. #endif
  4260. #ifdef WIN_MSWIN
  4261.   Nlm_RgnTool  ntool;
  4262.   HBRUSH       oldBrush;
  4263.  
  4264.   if (rgn != NULL && Nlm_currentHDC != NULL) {
  4265.     ntool = (Nlm_RgnTool) rgn;
  4266.     oldBrush = SelectObject (Nlm_currentHDC, GetStockObject (BLACK_BRUSH));
  4267.     if (oldBrush != NULL) {
  4268.       SelectObject (Nlm_currentHDC, oldBrush);
  4269.       FillRgn (Nlm_currentHDC, ntool, oldBrush);
  4270.     }
  4271.   }
  4272. #endif
  4273. #ifdef WIN_X
  4274. #endif
  4275. }
  4276.  
  4277. extern void Nlm_InvertRgn (Nlm_RegioN rgn)
  4278.  
  4279. {
  4280. #ifdef WIN_MAC
  4281.   Nlm_RgnTool  ntool;
  4282.  
  4283.   if (rgn != NULL) {
  4284.     ntool = (Nlm_RgnTool) rgn;
  4285.     InvertRgn (ntool);
  4286.   }
  4287. #endif
  4288. #ifdef WIN_MSWIN
  4289.   Nlm_RgnTool  ntool;
  4290.  
  4291.   if (rgn != NULL && Nlm_currentHDC != NULL) {
  4292.     ntool = (Nlm_RgnTool) rgn;
  4293.     InvertRgn (Nlm_currentHDC, ntool);
  4294.   }
  4295. #endif
  4296. #ifdef WIN_X
  4297. #endif
  4298. }
  4299.  
  4300. extern void Nlm_ClipRect (Nlm_RectPtr r)
  4301.  
  4302. {
  4303. #ifdef WIN_MAC
  4304.   Nlm_RectTool  rtool;
  4305.  
  4306.   if (r != NULL) {
  4307.     Nlm_RecTToRectTool (r, &rtool);
  4308.     ClipRect (&rtool);
  4309.   }
  4310. #endif
  4311. #ifdef WIN_MSWIN
  4312.   HRGN  hRgnClip;
  4313.  
  4314.   if (r != NULL && Nlm_currentHDC != NULL) {
  4315.     hRgnClip = CreateRectRgn (r->left, r->top, r->right, r->bottom);
  4316.     SelectClipRgn (Nlm_currentHDC, hRgnClip);
  4317.     DeleteObject (hRgnClip);
  4318.   }
  4319. #endif
  4320. #ifdef WIN_X
  4321.   Nlm_RectTool  rtool;
  4322.  
  4323.   if (r != NULL && Nlm_currentXDisplay != NULL && Nlm_currentXGC != NULL) {
  4324.     Nlm_RecTToRectTool (r, &rtool);
  4325.     rtool.x -= Nlm_XOffset;
  4326.     rtool.y -= Nlm_YOffset;
  4327.     XSetClipRectangles (Nlm_currentXDisplay, Nlm_currentXGC, 0, 0, &rtool, 1, Unsorted);
  4328.     if (Nlm_clpRgn != NULL) {
  4329.       XDestroyRegion ((Nlm_RgnTool) Nlm_clpRgn);
  4330.       Nlm_clpRgn = NULL;
  4331.     }
  4332.     Nlm_clpRgn = (Nlm_RegioN) XCreateRegion ();
  4333.     XUnionRectWithRegion (&rtool, (Nlm_RgnTool) Nlm_clpRgn, (Nlm_RgnTool) Nlm_clpRgn);
  4334.     XOffsetRegion ((Nlm_RgnTool) Nlm_clpRgn, Nlm_XOffset, Nlm_YOffset);
  4335.   }
  4336. #endif
  4337. }
  4338.  
  4339. extern void Nlm_ClipRgn (Nlm_RegioN rgn)
  4340.  
  4341. {
  4342. #ifdef WIN_MAC
  4343.   Nlm_RgnTool  ntool;
  4344.  
  4345.   if (rgn != NULL) {
  4346.     ntool = (Nlm_RgnTool) rgn;
  4347.     SetClip (ntool);
  4348.   }
  4349. #endif
  4350. #ifdef WIN_MSWIN
  4351.   Nlm_RgnTool  ntool;
  4352.  
  4353.   if (rgn != NULL && Nlm_currentHDC != NULL) {
  4354.     ntool = (Nlm_RgnTool) rgn;
  4355.     SelectClipRgn (Nlm_currentHDC, ntool);
  4356.   }
  4357. #endif
  4358. #ifdef WIN_X
  4359.   Nlm_RgnTool  ntool1;
  4360.   Nlm_RgnTool  ntool2;
  4361.  
  4362.   if (rgn != NULL && Nlm_currentXDisplay != NULL && Nlm_currentXGC != NULL) {
  4363.     ntool1 = XCreateRegion ();
  4364.     ntool2 = XCreateRegion ();
  4365.     XUnionRegion ((Nlm_RgnTool) rgn, ntool1, ntool2);
  4366.     XOffsetRegion (ntool2, -Nlm_XOffset, -Nlm_YOffset);
  4367.     XSetRegion (Nlm_currentXDisplay, Nlm_currentXGC, ntool2);
  4368.     if (Nlm_clpRgn != NULL) {
  4369.       XDestroyRegion ((Nlm_RgnTool) Nlm_clpRgn);
  4370.       Nlm_clpRgn = NULL;
  4371.     }
  4372.     Nlm_clpRgn = (Nlm_RegioN) XCreateRegion ();
  4373.     XUnionRegion ((Nlm_RgnTool) rgn, ntool1, (Nlm_RgnTool) Nlm_clpRgn);
  4374.     XOffsetRegion ((Nlm_RgnTool) Nlm_clpRgn, -Nlm_XOffset, -Nlm_YOffset);
  4375.     XDestroyRegion (ntool1);
  4376.     XDestroyRegion (ntool2);
  4377.   }
  4378. #endif
  4379. }
  4380.  
  4381. extern void Nlm_ResetClip (void)
  4382.  
  4383. {
  4384. #ifdef WIN_MAC
  4385.   Nlm_RecT      r;
  4386.   Nlm_RectTool  rtool;
  4387.  
  4388.   Nlm_LoadRect (&r, -32767, -32767, 32767, 32767);
  4389.   Nlm_RecTToRectTool (&r, &rtool);
  4390.   ClipRect (&rtool);
  4391. #endif
  4392. #ifdef WIN_MSWIN
  4393.   if (Nlm_currentHDC != NULL) {
  4394.     SelectClipRgn (Nlm_currentHDC, NULL);
  4395.   }
  4396. #endif
  4397. #ifdef WIN_X
  4398.   if (Nlm_currentXDisplay != NULL && Nlm_currentXGC != NULL) {
  4399.     XSetClipMask (Nlm_currentXDisplay, Nlm_currentXGC, None);
  4400.     if (Nlm_clpRgn != NULL) {
  4401.       XDestroyRegion ((Nlm_RgnTool) Nlm_clpRgn);
  4402.       Nlm_clpRgn = NULL;
  4403.     }
  4404.   }
  4405. #endif
  4406. }
  4407.  
  4408. extern void Nlm_ValidRect (Nlm_RectPtr r)
  4409.  
  4410. {
  4411. #ifdef WIN_MAC
  4412.   Nlm_RectTool  rtool;
  4413.  
  4414.   if (r != NULL) {
  4415.     Nlm_RecTToRectTool (r, &rtool);
  4416.     ValidRect (&rtool);
  4417.   }
  4418. #endif
  4419. #ifdef WIN_MSWIN
  4420.   Nlm_RectTool  rtool;
  4421.  
  4422.   if (r != NULL && Nlm_currentHWnd != NULL) {
  4423.     Nlm_RecTToRectTool (r, &rtool);
  4424.     ValidateRect (Nlm_currentHWnd, &rtool);
  4425.   }
  4426. #endif
  4427. #ifdef WIN_X
  4428. #endif
  4429. }
  4430.  
  4431. extern void Nlm_InvalRect (Nlm_RectPtr r)
  4432.  
  4433. {
  4434. #ifdef WIN_MAC
  4435.   Nlm_RectTool  rtool;
  4436.  
  4437.   if (r != NULL) {
  4438.     Nlm_RecTToRectTool (r, &rtool);
  4439.     InvalRect (&rtool);
  4440.   }
  4441. #endif
  4442. #ifdef WIN_MSWIN
  4443.   Nlm_RectTool  rtool;
  4444.  
  4445.   if (r != NULL && Nlm_currentHWnd != NULL) {
  4446.     Nlm_RecTToRectTool (r, &rtool);
  4447.     InvalidateRect (Nlm_currentHWnd, &rtool, TRUE);
  4448.   }
  4449. #endif
  4450. #ifdef WIN_X
  4451.   Nlm_RectTool  rtool;
  4452.  
  4453.   if (r != NULL && Nlm_currentXDisplay != NULL && Nlm_currentXWindow != 0) {
  4454.     Nlm_RecTToRectTool (r, &rtool);
  4455.     XClearArea (Nlm_currentXDisplay, Nlm_currentXWindow,
  4456.                 rtool.x - Nlm_XOffset, rtool.y - Nlm_YOffset,
  4457.                 rtool.width, rtool.height, TRUE);
  4458.   }
  4459. #endif
  4460. }
  4461.  
  4462. extern void Nlm_ValidRgn (Nlm_RegioN rgn)
  4463.  
  4464. {
  4465. #ifdef WIN_MAC
  4466.   if (rgn != NULL) {
  4467.     ValidRgn ((Nlm_RgnTool) rgn);
  4468.   }
  4469. #endif
  4470. #ifdef WIN_MSWIN
  4471.   if (rgn != NULL && Nlm_currentHWnd != NULL) {
  4472.     ValidateRgn (Nlm_currentHWnd, (Nlm_RgnTool) rgn);
  4473.   }
  4474. #endif
  4475. #ifdef WIN_X
  4476. #endif
  4477. }
  4478.  
  4479. extern void Nlm_InvalRgn (Nlm_RegioN rgn)
  4480.  
  4481. {
  4482. #ifdef WIN_MAC
  4483.   if (rgn != NULL) {
  4484.     InvalRgn ((Nlm_RgnTool) rgn);
  4485.   }
  4486. #endif
  4487. #ifdef WIN_MSWIN
  4488.   if (rgn != NULL && Nlm_currentHWnd != NULL) {
  4489.     InvalidateRgn (Nlm_currentHWnd, (Nlm_RgnTool) rgn, TRUE);
  4490.   }
  4491. #endif
  4492. #ifdef WIN_X
  4493.   Nlm_RgnTool   ntool1;
  4494.   Nlm_RgnTool   ntool2;
  4495.   Nlm_RectTool  rtool;
  4496.  
  4497.   if (rgn != NULL && Nlm_currentXDisplay != NULL &&
  4498.       Nlm_currentXGC != NULL && Nlm_currentXWindow != 0) {
  4499.     ntool1 = XCreateRegion ();
  4500.     ntool2 = XCreateRegion ();
  4501.     XUnionRegion ((Nlm_RgnTool) rgn, ntool1, ntool2);
  4502.     XOffsetRegion (ntool2, -Nlm_XOffset, -Nlm_YOffset);
  4503.     XSetRegion (Nlm_currentXDisplay, Nlm_currentXGC, ntool2);
  4504.     XClipBox (ntool2, &rtool);
  4505.     XClearArea (Nlm_currentXDisplay, Nlm_currentXWindow, rtool.x,
  4506.                 rtool.y, rtool.width, rtool.height, TRUE);
  4507.     XDestroyRegion (ntool1);
  4508.     XDestroyRegion (ntool2);
  4509.     if (Nlm_clpRgn != NULL) {
  4510.       ntool1 = XCreateRegion ();
  4511.       ntool2 = XCreateRegion ();
  4512.       XUnionRegion ((Nlm_RgnTool) Nlm_clpRgn, ntool1, ntool2);
  4513.       XOffsetRegion (ntool2, -Nlm_XOffset, -Nlm_YOffset);
  4514.       XSetRegion (Nlm_currentXDisplay, Nlm_currentXGC, ntool2);
  4515.       XDestroyRegion (ntool1);
  4516.       XDestroyRegion (ntool2);
  4517.     } else {
  4518.       XSetClipMask (Nlm_currentXDisplay, Nlm_currentXGC, None);
  4519.     }
  4520.   }
  4521. #endif
  4522. }
  4523.  
  4524. extern void Nlm_CopyBits (Nlm_RectPtr r, Nlm_VoidPtr source)
  4525.  
  4526. {
  4527. #ifdef WIN_MAC
  4528.   BitMap    dstBits;
  4529.   Nlm_Int2  mode;
  4530.   PenState  pnState;
  4531.   GrafPtr   port;
  4532.   Rect      rect;
  4533.   BitMap    srcBits;
  4534.   Rect      srcRect;
  4535.  
  4536.   if (r != NULL && source != NULL) {
  4537.     GetPort (&port);
  4538.     GetPenState (&pnState);
  4539.     switch (pnState.pnMode) {
  4540.       case patCopy:
  4541.         mode = srcCopy;
  4542.         break;
  4543.       case patOr:
  4544.         mode = srcOr;
  4545.         break;
  4546.       case patXor:
  4547.         mode = srcXor;
  4548.         break;
  4549.       case patBic:
  4550.         mode = srcBic;
  4551.         break;
  4552.       default:
  4553.         mode = srcCopy;
  4554.         break;
  4555.     }
  4556.     Nlm_RecTToRectTool (r, &rect);
  4557.     srcRect = rect;
  4558.     OffsetRect (&srcRect, -rect.left, -rect.top);
  4559.     srcBits.baseAddr = (Ptr) source;
  4560.     srcBits.rowBytes = (rect.right - rect.left - 1) / 8 + 1;
  4561.     srcBits.bounds = srcRect;
  4562.     dstBits = port->portBits;
  4563.     CopyBits (&srcBits, &dstBits, &srcRect, &rect, mode, NULL);
  4564.   }
  4565. #endif
  4566. #ifdef WIN_MSWIN
  4567.   Nlm_Int2      cols;
  4568.   HBITMAP       hBitmap;
  4569.   HBITMAP       hOldBitmap;
  4570.   HDC           hMemoryDC;
  4571.   Nlm_IntD      i;
  4572.   Nlm_IntD      j;
  4573.   Nlm_Int4      mode;
  4574.   Nlm_Int4      num;
  4575.   Nlm_Boolean   odd;
  4576.   Nlm_Uint1Ptr  p;
  4577.   Nlm_Uint1Ptr  ptr;
  4578.   Nlm_Uint1Ptr  q;
  4579.   Nlm_IntD      rop2;
  4580.   Nlm_IntD      rows;
  4581.  
  4582.   if (r != NULL && source != NULL && Nlm_currentHDC != NULL) {
  4583.     rows = (r->right - r->left - 1) / 8 + 1;
  4584.     odd = (Nlm_Boolean) ((rows & 1) != 0);
  4585.     cols = r->bottom - r->top;
  4586.     num = rows * cols;
  4587.     if (odd) {
  4588.       num += cols;
  4589.     }
  4590.     ptr = (Nlm_Uint1Ptr) Nlm_MemNew ((Nlm_sizeT) num * sizeof (Nlm_Uint1));
  4591.     if (ptr != NULL) {
  4592.       p = source;
  4593.       q = ptr;
  4594.       for (i = 0; i < cols; i++) {
  4595.         j = 0;
  4596.         while (j < rows) {
  4597.           *q = *p;
  4598.           p++;
  4599.           q++;
  4600.           j++;
  4601.         }
  4602.         if (odd) {
  4603.           *q = 0;
  4604.           q++;
  4605.         }
  4606.       }
  4607.       q = ptr;
  4608.       while (num > 0) {
  4609.         *q = (Nlm_Uint1) ~(*q);
  4610.         q++;
  4611.         num--;
  4612.       }
  4613.       hBitmap = CreateBitmap (r->right - r->left, r->bottom - r->top,
  4614.                               1, 1, (LPSTR) ptr);
  4615.       hMemoryDC = CreateCompatibleDC (Nlm_currentHDC);
  4616.       hOldBitmap = SelectObject (hMemoryDC, hBitmap);
  4617.       if (hOldBitmap != NULL) {
  4618.         rop2 = GetROP2 (Nlm_currentHDC);
  4619.         switch (rop2) {
  4620.           case R2_COPYPEN:
  4621.             mode = SRCCOPY;
  4622.             break;
  4623.           case R2_MASKPEN:
  4624.             mode = SRCAND;
  4625.             break;
  4626.           case R2_NOTXORPEN:
  4627.             mode = 0x00990066;
  4628.             break;
  4629.           case R2_MERGENOTPEN:
  4630.             mode = MERGEPAINT;
  4631.             break;
  4632.           default:
  4633.             mode = WHITENESS;
  4634.             break;
  4635.         }
  4636.         BitBlt (Nlm_currentHDC, r->left, r->top,
  4637.                 r->right - r->left, r->bottom - r->top,
  4638.                 hMemoryDC, 0, 0, mode);
  4639.         SelectObject (hMemoryDC, hOldBitmap);
  4640.       }
  4641.       Nlm_MemFree (ptr);
  4642.       DeleteDC (hMemoryDC);
  4643.       DeleteObject (hBitmap);
  4644.     }
  4645.   }
  4646. #endif
  4647. #ifdef WIN_X
  4648.   Nlm_IntD      cols;
  4649.   Nlm_IntD      height;
  4650.   Nlm_IntD      i;
  4651.   Nlm_IntD      j;
  4652.   Nlm_Int4      num;
  4653.   Pixmap        pixmap;
  4654.   Nlm_Uint1Ptr  ptr;
  4655.   Nlm_Uint1Ptr  q;
  4656.   Nlm_IntD      rows;
  4657.   Nlm_IntD      width;
  4658.  
  4659.   if (r != NULL && source != NULL && Nlm_currentXDisplay != NULL &&
  4660.       Nlm_currentXWindow != 0 && Nlm_currentXGC != NULL) {
  4661.     rows = (r->right - r->left - 1) / 8 + 1;
  4662.     cols = r->bottom - r->top;
  4663.     num = rows * cols;
  4664.     ptr = (Nlm_Uint1Ptr) Nlm_MemNew ((Nlm_sizeT) num * sizeof (Nlm_Uint1));
  4665.     if (ptr != NULL) {
  4666.       Nlm_MemCopy (ptr, source, (Nlm_sizeT) num);
  4667.       q = ptr;
  4668.       while (num > 0) {
  4669.         *q = flip [*q];
  4670.         q++;
  4671.         num--;
  4672.       }
  4673.       width = r->right - r->left;
  4674.       height = r->bottom - r->top;
  4675.       pixmap = XCreateBitmapFromData (Nlm_currentXDisplay, Nlm_currentXWindow,
  4676.                                       (char *) ptr, width, height);
  4677.       if (currentMode != MERGE_MODE) {
  4678.         XCopyPlane (Nlm_currentXDisplay, pixmap, Nlm_currentXWindow,
  4679.                     Nlm_currentXGC, 0, 0, width, height,
  4680.                     r->left - Nlm_XOffset, r->top - Nlm_YOffset, 1);
  4681.       } else {
  4682.         XSetClipOrigin (Nlm_currentXDisplay, Nlm_currentXGC,
  4683.                         r->left - Nlm_XOffset, r->top - Nlm_YOffset);
  4684.         XSetClipMask (Nlm_currentXDisplay, Nlm_currentXGC, pixmap);
  4685.         XSetFunction (Nlm_currentXDisplay, Nlm_currentXGC, GXcopy);
  4686.         XCopyPlane (Nlm_currentXDisplay, pixmap, Nlm_currentXWindow,
  4687.                     Nlm_currentXGC, 0, 0, width, height,
  4688.                     r->left - Nlm_XOffset, r->top - Nlm_YOffset, 1);
  4689.         XSetFunction (Nlm_currentXDisplay, Nlm_currentXGC, GXand);
  4690.         XSetClipOrigin (Nlm_currentXDisplay, Nlm_currentXGC, 0, 0);
  4691.         if (Nlm_clpRgn != NULL) {
  4692.           XSetRegion (Nlm_currentXDisplay, Nlm_currentXGC, (Nlm_RgnTool) Nlm_clpRgn);
  4693.         } else {
  4694.           XSetClipMask (Nlm_currentXDisplay, Nlm_currentXGC, None);
  4695.         }
  4696.       }
  4697.       XFreePixmap (Nlm_currentXDisplay, pixmap);
  4698.       Nlm_MemFree (ptr);
  4699.     }
  4700.   }
  4701. #endif
  4702. }
  4703.  
  4704. #ifdef WIN_X
  4705. static Nlm_Uint4 Nlm_SetupColor (Colormap colormap, Nlm_Int2 red, Nlm_Int2 green, Nlm_Int2 blue)
  4706.  
  4707. {
  4708.   XColor  xcolor;
  4709.  
  4710.   xcolor.red = red << 8;
  4711.   xcolor.green = green << 8;
  4712.   xcolor.blue = blue << 8;
  4713.   if (XAllocColor (Nlm_currentXDisplay, colormap, &xcolor) == 0) {
  4714.     xcolor.pixel = WhitePixel (Nlm_currentXDisplay, Nlm_currentXScreen);
  4715.   }
  4716.   return xcolor.pixel;
  4717. }
  4718. #endif
  4719.  
  4720. extern void Nlm_SetUpDrawingTools (void)
  4721.  
  4722. {
  4723. #ifdef WIN_MAC
  4724.   RgnPtr     rptr;
  4725.   SysEnvRec  sysenv;
  4726.  
  4727.   Nlm_scrollRgn = (Nlm_RegioN) (NewRgn ());
  4728.  
  4729.   Nlm_updateRgn = (Nlm_RegioN) (NewRgn ());
  4730.   SetRectRgn ((Nlm_RgnTool) Nlm_updateRgn, -32768, -32768, 32767, 32767);
  4731.   HLock ((Handle) Nlm_updateRgn);
  4732.   rptr = (RgnPtr) *((Handle) Nlm_updateRgn);
  4733.   Nlm_RectToolToRecT (&(rptr->rgnBBox), &Nlm_updateRect);
  4734.   HUnlock ((Handle) Nlm_updateRgn);
  4735.  
  4736.   Nlm_fontList = NULL;
  4737.   Nlm_fontInUse = NULL;
  4738.   Nlm_systemFont = (Nlm_FonT) Nlm_HandNew (sizeof (Nlm_FontRec));
  4739.   Nlm_LoadFontData (Nlm_systemFont, NULL, "", 12, 0, FALSE,
  4740.                     FALSE, FALSE, 0, 0, NULL, NULL);
  4741.   Nlm_programFont = (Nlm_FonT) Nlm_HandNew (sizeof (Nlm_FontRec));
  4742.   Nlm_LoadFontData (Nlm_programFont, NULL, "", 9, 0, FALSE,
  4743.                     FALSE, FALSE, 4, 0, NULL, NULL);
  4744.   Nlm_fontList = NULL;
  4745.   Nlm_fontInUse = Nlm_systemFont;
  4746.  
  4747.   Nlm_stdAscent = Nlm_Ascent ();
  4748.   Nlm_stdDescent = Nlm_Descent ();
  4749.   Nlm_stdLeading = Nlm_Leading ();
  4750.   Nlm_stdFontHeight = Nlm_FontHeight ();
  4751.   Nlm_stdLineHeight = Nlm_LineHeight ();
  4752.   Nlm_stdCharWidth = Nlm_MaxCharWidth ();
  4753.   SysEnvirons (1, &sysenv);
  4754.   hasColorQD = sysenv.hasColorQD;
  4755.   if (hasColorQD) {
  4756.     Nlm_RGBforeColor.red = 0;
  4757.     Nlm_RGBforeColor.green = 0;
  4758.     Nlm_RGBforeColor.blue = 0;
  4759.     Nlm_RGBbackColor.red = 65535;
  4760.     Nlm_RGBbackColor.green = 65535;
  4761.     Nlm_RGBbackColor.blue = 65535;
  4762.   }
  4763. #endif
  4764. #ifdef WIN_MSWIN
  4765.   Nlm_RectTool  rtool;
  4766.  
  4767.   Nlm_scrollRgn = (Nlm_RegioN) (CreateRectRgn (0, 0, 0, 0));
  4768.  
  4769.   Nlm_updateRgn = (Nlm_RegioN) (CreateRectRgn (-32767, -32767, 32767, 32767));
  4770.   GetRgnBox ((Nlm_RgnTool) Nlm_updateRgn, &rtool);
  4771.   Nlm_RectToolToRecT (&rtool, &Nlm_updateRect);
  4772.  
  4773.   Nlm_fontList = NULL;
  4774.   Nlm_fontInUse = NULL;
  4775.   Nlm_systemFont = (Nlm_FonT) Nlm_HandNew (sizeof (Nlm_FontRec));
  4776.   Nlm_LoadFontData (Nlm_systemFont, NULL, "", 0, 0, FALSE, FALSE, FALSE,
  4777.                     0, 0, GetStockObject (SYSTEM_FONT), NULL);
  4778.   Nlm_programFont = (Nlm_FonT) Nlm_HandNew (sizeof (Nlm_FontRec));
  4779.   Nlm_LoadFontData (Nlm_programFont, NULL, "", 0, 0, FALSE, FALSE, FALSE,
  4780.                     0, 0, GetStockObject (ANSI_FIXED_FONT), NULL);
  4781.   Nlm_fontList = NULL;
  4782.   Nlm_fontInUse = Nlm_systemFont;
  4783.  
  4784.   Nlm_stdAscent = Nlm_Ascent ();
  4785.   Nlm_stdDescent = Nlm_Descent ();
  4786.   Nlm_stdLeading = Nlm_Leading ();
  4787.   Nlm_stdFontHeight = Nlm_FontHeight ();
  4788.   Nlm_stdLineHeight = Nlm_LineHeight ();
  4789.   Nlm_stdCharWidth = Nlm_MaxCharWidth ();
  4790.  
  4791.   blackColor = RGB (0, 0, 0);
  4792.   redColor = RGB (255, 0, 0);
  4793.   greenColor = RGB (0, 255, 0);
  4794.   blueColor = RGB (0, 0, 255);
  4795.   cyanColor = RGB (0, 255, 255);
  4796.   magentaColor = RGB (255, 0, 255);
  4797.   yellowColor = RGB (255, 255, 0);
  4798.   whiteColor = RGB (255, 255, 255);
  4799.  
  4800.   hBlackPen = GetStockObject (BLACK_PEN);
  4801.   hNullPen = GetStockObject (NULL_PEN);
  4802.   hWhitePen = GetStockObject (WHITE_PEN);
  4803.   hBlackBrush = GetStockObject (BLACK_BRUSH);
  4804.   hDkGrayBrush = GetStockObject (DKGRAY_BRUSH);
  4805.   hGrayBrush = GetStockObject (GRAY_BRUSH);
  4806.   hHollowBrush = GetStockObject (HOLLOW_BRUSH);
  4807.   hLtGrayBrush = GetStockObject (LTGRAY_BRUSH);
  4808.   hNullBrush = GetStockObject (NULL_BRUSH);
  4809.   hWhiteBrush = GetStockObject (WHITE_BRUSH);
  4810.   hAnsiFixedFont = GetStockObject (ANSI_FIXED_FONT);
  4811.   hAnsiVarFont = GetStockObject (ANSI_VAR_FONT);
  4812.   hDeviceDefaultFont = GetStockObject (DEVICE_DEFAULT_FONT);
  4813.   hOemFixedFont = GetStockObject (OEM_FIXED_FONT);
  4814.   hSystemFont = GetStockObject (SYSTEM_FONT);
  4815.   hSystemFixedFont = GetStockObject (SYSTEM_FIXED_FONT);
  4816. #endif
  4817. #ifdef WIN_X
  4818.   Colormap      colormap;
  4819.   XFontStruct   *f;
  4820.   Nlm_Int2      i;
  4821.   Nlm_Uint2     inv;
  4822.   Nlm_Int2      j;
  4823.   XFontStruct   *p;
  4824.   Nlm_RecT      r;
  4825.   Nlm_RectTool  rtool;
  4826.   Nlm_Uint2     val;
  4827.  
  4828.   Nlm_scrollRgn = (Nlm_RegioN) (XCreateRegion ());
  4829.  
  4830.   Nlm_updateRgn = (Nlm_RegioN) (XCreateRegion ());
  4831.   Nlm_LoadRect (&r, -32767, -32767, 32767, 32767);
  4832.   Nlm_RecTToRectTool (&r, &rtool);
  4833.   XUnionRectWithRegion (&rtool, (Nlm_RgnTool) Nlm_updateRgn, (Nlm_RgnTool) Nlm_updateRgn);
  4834.   Nlm_RectToolToRecT (&rtool, &Nlm_updateRect);
  4835.  
  4836.   emptyRgn = XCreateRegion ();
  4837.  
  4838.   Nlm_fontList = NULL;
  4839.   Nlm_fontInUse = NULL;
  4840.   f = Nlm_XLoadQueryFont (Nlm_currentXDisplay, "-*-helvetica-bold-r-*--14-*", TRUE);
  4841.   Nlm_systemFont = (Nlm_FonT) Nlm_HandNew (sizeof (Nlm_FontRec));
  4842.   Nlm_LoadFontData (Nlm_systemFont, NULL, "", 12, 0, FALSE,
  4843.                     FALSE, FALSE, 0, 0, f, NULL);
  4844.   p = Nlm_XLoadQueryFont (Nlm_currentXDisplay, "-*-fixed-medium-r-*--13-*", FALSE);
  4845.   if (p == NULL) {
  4846.     p = Nlm_XLoadQueryFont (Nlm_currentXDisplay, "-*-courier-medium-r-*--12-*", FALSE);
  4847.   }
  4848.   if (p == NULL) {
  4849.     p = Nlm_XLoadQueryFont (Nlm_currentXDisplay, "8x13", FALSE);
  4850.   }
  4851.   if (p == NULL) {
  4852.     p = Nlm_XLoadQueryFont (Nlm_currentXDisplay, "9x15", TRUE);
  4853.   }
  4854.   Nlm_programFont = (Nlm_FonT) Nlm_HandNew (sizeof (Nlm_FontRec));
  4855.   Nlm_LoadFontData (Nlm_programFont, NULL, "", 9, 0, FALSE,
  4856.                     FALSE, FALSE, 4, 0, p, NULL);
  4857.   Nlm_fontList = NULL;
  4858.   Nlm_fontInUse = Nlm_systemFont;
  4859.  
  4860.   XSetFont (Nlm_currentXDisplay, Nlm_currentXGC, f->fid);
  4861.   currentFont = f;
  4862.   Nlm_stdAscent = Nlm_Ascent ();
  4863.   Nlm_stdDescent = Nlm_Descent ();
  4864.   Nlm_stdLeading = Nlm_Leading ();
  4865.   Nlm_stdFontHeight = Nlm_FontHeight ();
  4866.   Nlm_stdLineHeight = Nlm_LineHeight ();
  4867.   Nlm_stdCharWidth = Nlm_MaxCharWidth ();
  4868.  
  4869.   hasColor = FALSE;
  4870.   if (Nlm_currentXDisplay != NULL) {
  4871.     hasColor = (XDisplayCells (Nlm_currentXDisplay, Nlm_currentXScreen) > 2);
  4872.     if (hasColor) {
  4873.       colormap = DefaultColormap (Nlm_currentXDisplay, Nlm_currentXScreen);
  4874.       whiteColor = WhitePixel (Nlm_currentXDisplay, Nlm_currentXScreen);
  4875.       blackColor = BlackPixel (Nlm_currentXDisplay, Nlm_currentXScreen);
  4876.       redColor = Nlm_SetupColor (colormap, 255, 0, 0);
  4877.       greenColor = Nlm_SetupColor (colormap, 0, 255, 0);
  4878.       blueColor = Nlm_SetupColor (colormap, 0, 0, 255);
  4879.       cyanColor = Nlm_SetupColor (colormap, 0, 255, 255);
  4880.       magentaColor = Nlm_SetupColor (colormap, 255, 0, 255);
  4881.       yellowColor = Nlm_SetupColor (colormap, 255, 255, 0);
  4882.     } else {
  4883.       whiteColor = WhitePixel (Nlm_currentXDisplay, Nlm_currentXScreen);
  4884.       blackColor = BlackPixel (Nlm_currentXDisplay, Nlm_currentXScreen);
  4885.       redColor = BlackPixel (Nlm_currentXDisplay, Nlm_currentXScreen);
  4886.       greenColor = BlackPixel (Nlm_currentXDisplay, Nlm_currentXScreen);
  4887.       blueColor = BlackPixel (Nlm_currentXDisplay, Nlm_currentXScreen);
  4888.       cyanColor = BlackPixel (Nlm_currentXDisplay, Nlm_currentXScreen);
  4889.       magentaColor = BlackPixel (Nlm_currentXDisplay, Nlm_currentXScreen);
  4890.       yellowColor = BlackPixel (Nlm_currentXDisplay, Nlm_currentXScreen);
  4891.     }
  4892.   }
  4893.   fontInfo.fid = 0;
  4894.   for (i = 0; i < 256; i++) {
  4895.     inv = 0;
  4896.     val = (Nlm_Uint2) i;
  4897.     for (j = 0; j < 8; j++) {
  4898.       inv = (inv << 1);
  4899.       inv += (val % 2);
  4900.       val = (val >> 1);
  4901.     }
  4902.     flip [i] = inv;
  4903.   }
  4904.  
  4905.   Nlm_XbackColor = whiteColor;
  4906.   Nlm_XforeColor = blackColor;
  4907.   Nlm_XOffset = 0;
  4908.   Nlm_YOffset = 0;
  4909.   Nlm_clpRgn = NULL;
  4910. #endif
  4911. }
  4912.  
  4913. extern void Nlm_CleanUpDrawingTools (void)
  4914.  
  4915. {
  4916.   Nlm_FonT      f;
  4917.   Nlm_FontData  fdata;
  4918.  
  4919.   Nlm_ResetDrawingTools ();
  4920. #ifdef WIN_MOTIF
  4921.   Nlm_GetFontData (Nlm_systemFont, &fdata);
  4922.   if (fdata.handle != NULL) {
  4923.     XFreeFont (Nlm_currentXDisplay, fdata.handle);
  4924.   }
  4925.   Nlm_GetFontData (Nlm_programFont, &fdata);
  4926.   if (fdata.handle != NULL) {
  4927.     XFreeFont (Nlm_currentXDisplay, fdata.handle);
  4928.   }
  4929. #endif
  4930.   Nlm_HandFree (Nlm_systemFont);
  4931.   Nlm_HandFree (Nlm_programFont);
  4932.   f = Nlm_fontList;
  4933.   while (f != NULL) {
  4934.     Nlm_GetFontData (f, &fdata);
  4935. #ifdef WIN_MSWIN
  4936.     if (fdata.handle != NULL) {
  4937.       DeleteObject (fdata.handle);
  4938.     }
  4939. #endif
  4940. #ifdef WIN_MOTIF
  4941.     if (fdata.handle != NULL) {
  4942.       XFreeFont (Nlm_currentXDisplay, fdata.handle);
  4943.     }
  4944. #endif
  4945.     Nlm_HandFree (f);
  4946.     f = fdata.next;
  4947.   }
  4948. #ifdef WIN_MOTIF
  4949.   XDestroyRegion (emptyRgn);
  4950. #endif
  4951. }
  4952.